Default operator strawman - ||| rather than ??

Brendan Eich brendan at
Wed Jun 13 11:18:52 PDT 2012

Tab Atkins Jr. wrote:
> Okay, further testing shows that my knowledge was incomplete.  Null
> and undefined compare as double-equal, but neither are double-equal to
> other falsey values.

This is intentional, believe it or don't :-P.

In ancient days, void 0 was the only way to spell undefined, and users 
immediately tested o.p != null to existing-check. There was even some 
confusion where missing array elements in primordial JS evaluated to 
null not undefined. Argh, I had made myself forget that, now I remember.

> However, my argument stands - being undefined-specific is not
> arbitrary, because that's what is actually returned by such things.
> Both args without values and properties that don't exist give the
> value undefined when you try to reference them.

Agree still. I do not see use-cases for including null. Maybe they 
exist, though -- someone please cite some github-hosted JS.

Even the Node workaround/premature-optimization of storing null rather 
than using delete doesn't argue for defaulting based on LHS value in 
{null, undefined}.

>   Using a double-equal
> check against null to test for whether something is undefined only
> works because double-equal is pretty screwed up.

It is screwed up but for reasons. Bad reasons, kind of like history or 
biology. Not just Homer Simpson "Life is just a bunch of things that 
happen" randomness, mind you! :-P

The most principled reason I've heard, IIRC from @jashkenas, is that 
null and undefined are confusingly similar, in part due to being ==. 
This is true, but I still do not see actual use-cases where null is 
passed into code that uses || to select a default value. Would love to 
see such real-world code.


More information about the es-discuss mailing list