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 the following?!:

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

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -