{"action":"created","issue":{"url":"https://api.github.com/repos/getify/You-Dont-Know-JS/issues/727","repository_url":"https://api.github.com/repos/getify/You-Dont-Know-JS","labels_url":"https://api.github.com/repos/getify/You-Dont-Know-JS/issues/727/labels{/name}","comments_url":"https://api.github.com/repos/getify/You-Dont-Know-JS/issues/727/comments","events_url":"https://api.github.com/repos/getify/You-Dont-Know-JS/issues/727/events","html_url":"https://github.com/getify/You-Dont-Know-JS/issues/727","id":153693819,"number":727,"title":"\"es6 & beyond\": ch3, default exports","user":{"login":"doffltmiw","id":627032,"avatar_url":"https://avatars.githubusercontent.com/u/627032?v=3","gravatar_id":"","url":"https://api.github.com/users/doffltmiw","html_url":"https://github.com/doffltmiw","followers_url":"https://api.github.com/users/doffltmiw/followers","following_url":"https://api.github.com/users/doffltmiw/following{/other_user}","gists_url":"https://api.github.com/users/doffltmiw/gists{/gist_id}","starred_url":"https://api.github.com/users/doffltmiw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doffltmiw/subscriptions","organizations_url":"https://api.github.com/users/doffltmiw/orgs","repos_url":"https://api.github.com/users/doffltmiw/repos","events_url":"https://api.github.com/users/doffltmiw/events{/privacy}","received_events_url":"https://api.github.com/users/doffltmiw/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/getify/You-Dont-Know-JS/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-05-09T02:42:04Z","updated_at":"2016-05-16T20:24:31Z","closed_at":null,"body":"> There's a subtle nuance to default export syntax that you should pay close attention to. Compare these two snippets:\r\n> \r\n> function foo(..) {\r\n>     // ..\r\n> }\r\n> \r\n> export default foo;\r\n> And this one:\r\n> \r\n> function foo(..) {\r\n>     // ..\r\n> }\r\n> \r\n> export { foo as default };\r\n> In the first snippet, you are exporting a binding to the function expression value at that moment, not to the identifier foo. In other words, export default .. takes an expression. If you later assign foo to a different value inside your module, the module import still reveals the function originally exported, not the new value.\r\n> \r\n> By the way, the first snippet could also have been written as:\r\n> \r\n> export default function foo(..) {\r\n>     // ..\r\n> }\r\n> Warning: Although the function foo.. part here is technically a function expression, for the purposes of the internal scope of the module, it's treated like a function declaration, in that the foo name is bound in the module's top-level scope (often called \"hoisting\"). The same is true for export default class Foo... However, while you can do export var foo = .., you currently cannot do export default var foo = .. (or let or const), in a frustrating case of inconsistency. At the time of this writing, there's already discussion of adding that capability in soon, post-ES6, for consistency sake.\r\n\r\nIs this description correct? [This book](http://exploringjs.com/es6/ch_modules.html#_default-exports-one-per-module) says a function is a declaration in `exports default function () { ... } `, and an expression in `export default (function () { ... });`.\r\n"},"comment":{"url":"https://api.github.com/repos/getify/You-Dont-Know-JS/issues/comments/219536606","html_url":"https://github.com/getify/You-Dont-Know-JS/issues/727#issuecomment-219536606","issue_url":"https://api.github.com/repos/getify/You-Dont-Know-JS/issues/727","id":219536606,"user":{"login":"getify","id":150330,"avatar_url":"https://avatars.githubusercontent.com/u/150330?v=3","gravatar_id":"","url":"https://api.github.com/users/getify","html_url":"https://github.com/getify","followers_url":"https://api.github.com/users/getify/followers","following_url":"https://api.github.com/users/getify/following{/other_user}","gists_url":"https://api.github.com/users/getify/gists{/gist_id}","starred_url":"https://api.github.com/users/getify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getify/subscriptions","organizations_url":"https://api.github.com/users/getify/orgs","repos_url":"https://api.github.com/users/getify/repos","events_url":"https://api.github.com/users/getify/events{/privacy}","received_events_url":"https://api.github.com/users/getify/received_events","type":"User","site_admin":false},"created_at":"2016-05-16T20:24:31Z","updated_at":"2016-05-16T20:24:31Z","body":"For posterity, let's clear up the question:\r\n\r\n> So, does your description of \"If you later assign foo to a different value inside your module, the module import still reveals the function originally exported, not the new value.\" still apply to the export default function foo(..) { ... }\r\n\r\nNo, it does not apply. An `export default function foo() { .. }` can later be redefined in the module and the redefinition is what's seen on import side.\r\n\r\n> or it's only relevant for the case when export default takes an expression?\r\n\r\nYep."}}