You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In What about &&? section we have the following code.
function foo() {
console.log( a );
}
var a = 42;
a && foo(); // 42
result in comment should indicate that foo was called. but in fact we would get same result of "42" if first operand had been called (like in || operator). i think results of a and foo() should be different to make the example be clearer.
for example:
function foo() {
console.log("foo");
}
var a = 42;
a && foo(); // "foo"
The text was updated successfully, but these errors were encountered:
We're checking to see if a exists to see if we should call a function which depends on a. So this makes sense if you already understand short circuit evaluation to a degree, but the example does feel a little contrived.
It might be clearer if we were doing something with a instead of doing more than just console logging a on its own? Example:
function foo() {
console.log(a * 2);
}
var a = 42;
a && foo(); // "84"
In What about &&? section we have the following code.
result in comment should indicate that foo was called. but in fact we would get same result of "42" if first operand had been called (like in
||
operator). i think results ofa
andfoo()
should be different to make the example be clearer.for example:
The text was updated successfully, but these errors were encountered: