undefined being treated as a missing optional argument

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Apr 13 13:08:47 PDT 2012


On Apr 13, 2012, at 12:16 PM, Brendan Eich wrote:

> The story for JS is
> 
> undefined is "no value"
> null is "no object"

Yet there are many places in the language where undefined is not the same as no value.  For example:

let mapped1 = [,,"foo",,].map(v=>v+1);
let mapped2 =[undefined,undefined,"foo",undefined,undefined].map(v>v+1);

produce quite different values for mapped1 and mapped2.  

     obj.foo = undefined;
does not mean 
     delete obj.foo;

    new Array(undefined, undefined, undefined, undefined)
does not mean
     new Array()

Additionally,
    function (x = "default") {return x}
does not mean the same thing as
    function (x) { x= x || "default"; return x}
under either of the proposed default parameter value semantics.

Making f() and f(undefined) mean the something (but only sometimes, you have to look at the actual implementation of f to know for sure) seems to be add just another internal inconsistency that makes it harder to form a general conceptual model of the language.

Allen




More information about the es-discuss mailing list