Parenthesis have higher precedence than equality.
So from my understanding, the higher precedence is evaluated first.
Lets now assume I compare a
which is not defined:
if (a == 1) { .. // throws an exception because a is not defined
Actual case:
if (typeof a !== 'undefined' && (a == 1)) {
console.log(1)
} else {
console.log(2)
}
should be evaluated in this order:
- (typeof a !== 'undefined' && (a == 1))
- (a == 1)
- typeof a
- result from (3) !== 'undefined'
- "result from (4)" && "result from (2)"
But this would usually throw an exception if a is not defined but it doesn't.
Why is the left side of the equation evaluated first even though it has the lower precedence?
EDIT: I adapted the example from '||' to &&
just because ||
would always throw.