Why does “alert(3>2>1)” alert “false” [duplicate]

If you add parentheses to show how JavaScript is interpreting it, it gets much clearer:

alert( (3 > 2) > 1 );

Let’s pick this apart. First, it evaluates 3 > 2. Yes, three is greater than two. Therefore, you now have this:

alert( true > 1 );

true is coerced into a number. That number happens to be 1. 1 > 1 is obviously false. Therefore, the result is:

alert( false );

Leave a Comment