Obscure JavaScript

My colleague, pasted an interesting javaScript idiom to our developer chat, some time ago, and it immediately caught my attention. If you cast an array literal to a number, prepending it with a ‘+’ operator, it will evaluate to 0. var a = +[]; // a is 0 Heh, something so logical, yet obscure, immediately inspired me to take this a bit further. ...

September 13, 2011 · 3 min · ArtBIT