dotJS 2012 – Brian Leroux – WTFJS

Back in 2012 at dotJS – which I attended – Brian Leroux gave his talk WTFJS. Somehow the video of that talk got recommended on YouTube to me. It was fun watching this again 🙂

Gotta love coercion 😍

Also: Wat?

Can (a ==1 && a== 2 && a==3) ever evaluate to true?

Is it ever possible that (a ==1 && a== 2 && a==3) could evaluate to true, in JavaScript?

This is interview question asked by a major tech company. My answer was that it’s impossible. They said nothing is impossible. It happened 2 weeks back, but I’m still trying to find the answer. I know we never write such code in our day to day job, but I’m curious.

Betteridge’s Law of Headlines demands the answer to this question to be no, but given the fact that it’s question about JavaScript the answer – of course – is yes.

Here’s a hint: note the == that’s used, allowing for coercion to happen 😉

StackOverflow: Can (a ==1 && a== 2 && a==3) ever evaluate to true? →

Down the Rabbit Hole: Javascript in Wonderland

Talk by Claudia Hernández, on a few of Javascript’s oddities and (un)expected behaviors:


There’s a presentation embedded in this post. View it on Speaker Deck.

For a language originally created in 10 days it surely has a lot of quirks and perks many JS developers are unaware of. Sometimes, it might even seem like we fell down the rabbit hole only to find that NaN is actually a Number, undefined can be defined, +!![] equals 1, Array.sort() may not work as you suspected and so much other nonsense that can trip any JS developer’s mind.

Related: Equality in JavaScript, wtfjs, and – save best for last – wat