0

Why output 2?

Hi! Why output 2? console.log(0 || 1&&2 || 3)

22nd Oct 2019, 1:09 PM
Алексей Алексеев
Алексей Алексеев - avatar
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
22nd Oct 2019, 1:19 PM
Seb TheS
Seb TheS - avatar
+ 1
Thank you very much. I understand now.
22nd Oct 2019, 1:50 PM
Алексей Алексеев
Алексей Алексеев - avatar