Named versus default exports

Earlier, we saw that we used the export default: Holy moly this is interesting. What it does is, when we use import <varname> from './module', it assigns <varname> the value of the default export. Therefore, see the following:

// index.jsimport string from './module.js'console.log(string)

This will console-log Holy moly this is interesting.

This is called a default export.

A named export, on the other hand, has a name associated with it (the variable's name or the function's name). You'll have to import a named-export variable using destructuring syntax. This is because you can think of the export keyword as exporting a default value plus an object that contains all other exports you're doing (named exports). ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.