Reputation: 1
I am reading operator precedence on this page. It shows "===" has higher precedence than "||" operator. If it is true, then "a === doesThisHappen()" will run first. But why I did not get console.log('This happens!')?
var a;
a = 1;
function doesThisHappen() {
console.log('This happens!');
return 0;
}
if (a || a === doesThisHappen()) {
console.log('Something is there.');
}
Upvotes: 0
Views: 84
Reputation: 111219
Order of evaluation and operator precedence are orthogonal concepts. In a || b
the left side a
is evaluated first no matter what the right side b
contains. More over, if the left side evaluates to true the right side is not evaluated.
Upvotes: 3