Brandon Benvie (2013-11-11T19:37:44.000Z)
On 11/11/2013 11:31 AM, Corey Frang wrote:
> I hate to bring this up, as I'm sure I've missed a bunch of the 
> arguments that define WHY, but if this is the case, it seems 
> unintuitive to me that passing undefined still results in a default 
> param being set.
>
>
> function test(a = 1) { console.log(a); }
>
> test(); // gets 1 - yay
> test(undefined); // gets 1 - boo! Expect: undefined
>
> (sorry tab, forgot to reply all on the first reply :( )

The reason for this is so that you can do:

```js
function foo(bar) {
   return delegatedFoo("foo", bar);
}

function delegatedFoo(foo, bar = "bar") {
   return foo + bar;
}

foo(); // "foobar" and not "fooundefined"
```

This kind of argument-passing delegation is a very common in JS.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131111/85976cd9/attachment.html>
domenic at domenicdenicola.com (2013-11-15T18:56:10.233Z)
The reason for this is so that you can do:

```js
function foo(bar) {
   return delegatedFoo("foo", bar);
}

function delegatedFoo(foo, bar = "bar") {
   return foo + bar;
}

foo(); // "foobar" and not "fooundefined"
```

This kind of argument-passing delegation is a very common in JS.