+ 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 Réponses
+ 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
+ 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
+ 2
Because of the weakly typed nature of JS.
22nd Jul 2019, 1:35 AM
Sonic
Sonic - avatar