Reputation: 287
I know there can be only one "export default" in one file. Beside that, what are the differences? both of them can be imported by other files
Upvotes: 2
Views: 430
Reputation: 106
default export doesn't have to have a name in the exporting file
For example:
export default function doStuff() {...}
or export default function() {...}
Named export always has to have a value with a name. For example:
export function doStuff() {...}
Upvotes: 0
Reputation: 436
They change the way the exported bits are imported.
Importing a named export:
import {namedThing} from './otherFile.js';
Importing a default export:
import thing from './otherFile';
With a default export, you can rename the thing you are importing on the way in, like
import hoobajoob from './otherFile';
There are many other ways to do imports: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
Upvotes: 2