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

javascript, logical-operators, operators

Solution

The expression evaluates to `myvar` if `myvar` is falsey, and `foo()` if `myvar` is truthy. The following snippets are nearly identical.

var x = (myvar && foo());

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

Problem

``` (myVar && foo()) ``` What does the above code mean? What is it equivalent to? I think it runs on a single line.

Original source