Why does "alert(3>2>1)" alert "false"

javascript

Solution

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 );

Problem

I would like to ask why ``` alert(3>2>1); // (1) ``` Is returning FALSE in Javascript. I know that the correct is: ``` alert(3>2 && 2>1); // (2) ``` But the code 1 should return either an error message or either TRUE! Is there a specific reason that this equation returns FALSE?

Original source

Related problems