operators - What does (myVar && foo()) mean in JavaScript? -


(myvar && foo()) 

what above code mean? equivalent to?

i think runs on single line.

the expression evaluates myvar if myvar falsey, , foo() if myvar truthy. following snippets identical.

var x = (myvar && foo());  if(myvar){ var x = foo(); } else { var x = myvar; } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -