Today's Moment of Zen

by Jeremy Hinegardner

Today's Moment of Zen

Somehow, all the articles from James Mickens end up in my twitter stream. It is a thoroughly enjoyable time when it does.

This edition, To Wash It All Away, does not disappoint.

The nugget I learned today about JavaScript from James.

\r\n\t == false

WTF? I had to try it out.

    % node
    > "\r\n\t" == false

And of course, the explanation from James:

Heres why: the browser detects that the two operands have different types, so it converts false to 0 and retries the comparison. The operands still have different types (string and number), so the browser coerces \r\n\t into the number 0, because somehow, a non-zero number of characters is equal to 0. Voila0 equals 0! AWESOME. That explanation was like the plot to Inception, but the implanted idea was the correctness of your program has been coerced to false.

Really, I just had to share.