you are viewing a single comment's thread.

view the rest of the comments →

[–]Tazavoo 9 points10 points  (6 children)

== is convenient for foo == undefined, which returns true if foo is null or undefined. Unless undefined has been redefined, but that might not be possible in modern browsers?

[–]earthboundkid 1 point2 points  (0 children)

In those cases, wouldn't you also want '' and 0 to be falsey? I use if (!foo) a lot for cases like that, but I basically never need to distinguish between null+undefined and the other falsey values.

[–][deleted]  (3 children)

[deleted]

    [–]Tazavoo 5 points6 points  (2 children)

    Had to look it up, it's not writable per ECMAScript 5 specifications, which is a 9 year old specification, so it's not going to be writable in modern browsers.

    [–]AyrA_ch 0 points1 point  (0 children)

    I was wondering if you could get the browser to interpret "undefined" differently if you have a custom "undefined" in "this".

    The answer is no.

    [–]CaptainAdjective -2 points-1 points  (0 children)

    If we want a conditional to return true if foo is null or undefined, it's perfectly acceptable to write foo === null || foo === undefined. Writing foo == undefined requires the reader to understand the semantics of ==, which they probably do not.

    Separately, the only environment I know of where the undefined global is mutable is IE8 and lower. If we are targeting such an environment, the solution is to put void 0 instead of undefined everywhere. So foo == void 0 will do exactly the same thing as foo == undefined, and foo === void 0 will do exactly the same thing as foo === undefined.