Why is "export default var a = 1;" invalid syntax?

Brendan Eich brendan at mozilla.org
Mon Dec 15 20:50:05 PST 2014

Kevin Smith wrote:
>     ```js
>     export default function a() {}
>     a = 2;
>     ``` 
>     (This should be 2, right?)
> I *think* the "default" binding in this case would still point to the 
> function.  I find this particular example completely baffling, to be 
> honest.

This seems clear. As Dave said, he originally proposed an '=' in between 
'default' and the *expression* to evaluate on the right. That design 
remembrance should make clear that the default export is a function 
expression (not function declaration) with 'a' the name only in the 
scope of that function (either for recursion or as a downward funarg).

The 'default' binding won't be mutated via the final 'a = 2' statement, 
so the default-exported value is still the result of evaluating the 
function a(){} expression.


More information about the es-discuss mailing list