Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is 5 > 4 > 3 != (5 > 4 && 4 > 3) true in Javascript?

Tags:

javascript

Why is 5 > 4 > 3 != (5 > 4 && 4 > 3) true in Javascript?

So annoying!

like image 439
Tom Lehman Avatar asked Nov 29 '10 04:11

Tom Lehman


2 Answers

5 > 4 > 3 is evaluated like (5 > 4) > 3, then it's true > 3, which is false. Look

like image 66
cambraca Avatar answered Oct 04 '22 03:10

cambraca


JavaScript, in the great tradition of most languages that descend from C, does not support relational operator chaining.

like image 30
Ignacio Vazquez-Abrams Avatar answered Oct 04 '22 02:10

Ignacio Vazquez-Abrams