undefined being treated as a missing optional argument

Brendan Eich brendan at mozilla.org
Fri Apr 13 12:14:32 PDT 2012

David Herman wrote:
> Think of it as saying that the undefined value is the idiomatic way in JS to represent "no value for the expected type." The smelly thing then is to create API's that both use defaults and accept undefined as a valid input.

FTR, I'm on board with Arv, Dave, Russell, and probably others on this. 
I agree that we must not impose the combinatorial explosion. 
Alternatively, we must not require copy/paste of parameter default 
values across delegation graphs.

That leaves using undefined as the in-language defaulting sentinel as 
the "least worst" option. Teaching programmers to avoid giving a 
maybe-undefined-on-purpose parameter a default value (other than 
undefined!) is doable and I would be surprised if people wrote

   function foo(a = default_a) {...}

and wanted


to bind default_a to a.

(Again, if default_a is the value |undefined| then everything "just 
works", but writing

   function foo(a = undefined) {...}

is a silly way to write

   function foo(a) {...}



More information about the es-discuss mailing list