+ 8

Why is 4<2<4 true in JavaScript?

Why is 4<2<4 true in JavaScript?

20th Jul 2019, 3:10 PM
Francis Woli
Francis Woli - avatar
5 Answers
+ 28
4<2 gives 0 0<4 gives true
20th Jul 2019, 3:16 PM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 9
Francis Woli console.log(4<2<4) // true console.log((4<2)<4) // true console.log(4<2) // false console.log(false<2) // true Because false == 0 then 0<2 is true
20th Jul 2019, 3:18 PM
deeyae
deeyae - avatar
+ 5
It is called coercion
20th Jul 2019, 8:28 PM
Mirielle
Mirielle - avatar
+ 4
Because the expression is evaluated from LEFT TO RIGHT TWO at a time 🤗
21st Jul 2019, 3:08 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 3
true
21st Jul 2019, 4:04 AM
ULUGBEK ODILOV
ULUGBEK ODILOV - avatar