function foo( a, b ) {
a = a || '123';
b = b || 55;
document.write( a + ',' + b );
}
foo(); // prints: 123,55
foo('bar'); // prints: bar,55
foo('x', 'y'); // prints x,y
but:
foo(0,''); // prints: 123,55
why dont it print 0 ,55?
Because || tests for truthiness, and 0 is among the values that are considered to be false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With