A fast enjoyable “JS WTF?” put up for you right now. Should you load up your JavaScript console & enter:
5 < 4 < 3
You’d expect to see false, proper? Nevertheless, you may truly see true. WTF?
That is truly all the way down to the best way JavaScript evaluates this and operator priority. What it sees is:
(5 < 4) < 3
Which in flip offers
false < 3
JavaScript then coerces false into an integer 0:
0 < 3
And nil is certainly lower than 3, so we get true returned.
Not a lot realized from this one however it’s fairly a enjoyable factor to point out somebody & then clarify why. I will be making an attempt to do a number of these small “enjoyable” posts as there is a truthful few areas of “WTF?” in JavaScript, as everyone knows.
0
Subscribe to MarketingSolution.
Receive web development discounts & web design tutorials.
Now! Lets GROW Together!