News for hackers. Stuff that matters.
Re:Node.js is Cancer by stock_toaster on Sunday October 02, 2011 @04:37AM (#3062385)
> Someone doesn't know about the "foo == null" idiom (it's true if and only if x is null or undefined).

(preface: I am by no means a javascript guru)

Really? Double equals in javascript? I thought that was a no-no due to the type coercion that "==" does.

I get a reference error when I crack open a console and try your example idiom.

Re:Node.js is Cancer by ootachi on Sunday October 02, 2011 @04:40AM (#3062390)
Right, it doesn't work when you're testing whether foo is a bound name at all. In that case you need to use "window.foo" (or this.foo in Node).

And yeah, it's double equals. The coercion is exactly what allows "== null" to do the right thing in the presence of undefined. Contrary to popular belief, "0 == null", "'' == null", and "[] == null" are all false in JavaScript. "foo == null" doesn't test for falsiness, it just checks whether foo is null or undefined.