Functions argument default value

by Mohan 2012-09-20 23:29:05


Functions argument default value
function foo( a, b ) {

a = a || '123';
b = b || 55;
Print( a + ',' + b );
}

foo(); // prints: 123,55
foo('bar'); // prints: bar,55
foo('x', 'y'); // prints x,y
but:
foo(0,''); // prints: 123,55
because 0 and '' are evaluated as false !


832
like
0
dislike
0
mail
flag

You must LOGIN to add comments