javascript - Using expressions and logical operators in function arguments -
what mean have expressions logical operators passed argument function?!
for example:
myfunc(expr_1 || expr_2 || expr_3); is equivalent following?!:
var expr_all = expr_1 || expr_2 || expr_3; myfunc(expr_all); and if so, how supposed work if 3 expressions evaluate strings (as opposed booleans), or if expr_1 undefined or something?!
thanks.
myfunc(expr_1 || expr_2 || expr_3); equivalent thefollowing?!:
var expr_all = expr_1 || expr_2 || expr_3; myfunc(expr_all);
yes is. pass first truthy value function.
truthy values values not false,null,nan,"", 0,or undefined
this works because || logical or statement. return value of first object left right truthy. otherwise return false.
see these examples:
"a" || "b" //"a" "" || "b" //"b" "" || "" //"" "" || undefined //undefined "" || [] // []
Comments
Post a Comment