Chakradhari Jamili
Chakradhari Jamili

Reputation: 137

Behavior of inequalities expressed in javascript

console.log(10 > 9 < 8);

When I print this, I get the value true

Why is this so? Could someone please explain along with some documentation, if possible.

Upvotes: 1

Views: 123

Answers (2)

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382122

10 > 9 < 8

is

(10 > 9) <8

(because comparison operators are left-associative)

which is

true < 8

where true is casted (using ToNumber) to a number, 1

(details here)

Upvotes: 11

Ali Ezzat Odeh
Ali Ezzat Odeh

Reputation: 2163

10 > 9 => is true 

then true < 8 is true because true will be evaluated to 1

Upvotes: 6

Related Questions