typeof null

David Herman dherman at mozilla.com
Tue May 8 14:45:11 PDT 2012


On May 8, 2012, at 9:19 AM, Rick Waldron wrote:

> non-strict, non-opt-in:
> 
> typeof null === "null"; // false
> 
> implied opt-in:

Changing typeof null always seemed questionable to me in terms of value. It doesn't really give you significant new functionality, it just kinda seems "more sensible". But adding it would just make things *more* messy, for very little gain. Since we can't eliminate the old typeof semantics, we end up with the language having different semantics in different contexts.

And then once we moved to 1JS, it just seemed that much worse to have the variability, since the exact same code can have different meanings right near each other:

    var x = typeof null;
    module Foo {
        export var y = typeof null;
    }
    console.log(x)     // "object"
    console.log(Foo.y) // "null"

It's just not worth it.

OTOH, we could pretty easily add a new library function:

    import type from "@std";
    console.log(type(null)) // "null"

I'd support that.

Dave

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120508/460c3f7b/attachment.html>


More information about the es-discuss mailing list