+ 8
Why is 4<2<4 true in JavaScript?
Why is 4<2<4 true in JavaScript?
5 Réponses
+ 28
4<2 gives 0
0<4 gives true
+ 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
+ 4
Because the expression is evaluated from LEFT TO RIGHT TWO at a time 🤗
+ 3
true
+ 2
Because of the weakly typed nature of JS.