Why this code is error:
console.log(true&&false??true)
But this code is no error:
console.loge((true&&false)??true)
Or this example why B()
does not run:
function A() { console.log('called A'); return false; }
function B() { console.log('called B'); return false; }
function C() { console.log('called C'); return true; }
console.log(C() || B() && A());
// Logs:
// called C
// true
2
Answers
The answer to "why does this work this way" here is because it’s defined to work that way.
You can find the rules for short-circuiting logic and the precedence of operators and basically everything else about JavaScript in the MDN web documentation (other references are available):
For the first part of the question, see here.