Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JavaScript imports and exports: default and named
- a module can only have one default export:
export default A = //something
... and can be imported with any name:
import A from './A.js';
import B from './A.js';
import someothername from './A.js'
- named exports are imported by their exact name only, a module can have zero, one or more named exports
export const A = 1;
export const B = 2;
... these must be imported by name:
import { A } from './A.js';
import { B } from './A.js';
... this would fail if there's no named export called C
import { C } from './A.js';
... you can't change the name if there is no default export
import somethingelse from './A.js'; // this doesn't work
If there is a mix of default and named exports, you can import both styles at the same time
import A, {B, C} from '.A.js'; // assuming there is a default and B and C are named exports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment