Reputation: 148524
Javascript ( along with other languages ) won't evaluate :
right
side here : imTrue || imFalse
right
side here : imFalse && imTrue
But does those rules are also applies with *bitwise * operations ? ( couldn't find any mdn info)
e.g.
Upvotes: 0
Views: 100
Reputation: 382150
The right side in the logical operators you show isn't computed because they're short circuit operators.
There's no such thing for bitwise operators (yes, they're not just boolean operators, they're bitwise operators, which quite changes the problem).
A simple demonstration :
0 & (function(){ return console.log('evaluated'),1 })();
The main reason for short circuit operator isn't performance, it's the ability to avoid errors in such evaluations :
if (a && a.pretty) ...
It's hard to come with the need for short circuit protection when doing bitwise operations.
Note also that the weak typing of javascript makes it hard to evaluate when you don't need the right side. Luaan gives a good example : 1|2
.
Upvotes: 2