0
Why output 2?
Hi! Why output 2? console.log(0 || 1&&2 || 3)
2 Respostas
+ 3
&& has higher precedenceorder than ||.
x && y
Actually means:
x if x equals false, else y
Thus 1&&2 evaluates to 2
x || y
Actually means:
x if x equals true, else y
Thus 0 || 2 evaluates to 2,
and 2 || 3 also evaluates to 2.
0 || 1 && 2 || 3
-> 0 || 2 || 3
-> 2 || 3
-> 2
+ 1
Thank you very much. I understand now.