Default exports

suggest change

In addition to named imports, you can provide a default export.

// circle.js
export const PI = 3.14;
export default function area(radius) {
    return PI * radius * radius;
}

You can use a simplified syntax to import the default export.

import circleArea from './circle';
console.log(circleArea(4));

Note that a default export is implicitly equivalent to a named export with the name default, and the imported binding (circleArea above) is simply an alias. The previous module can be written like

import { default as circleArea } from './circle';
console.log(circleArea(4));

You can only have one default export per module. The name of the default export can be omitted.

// named export: must have a name
export const PI = 3.14;

// default export: name is not required
export default function (radius) {  
    return PI * radius * radius;
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Modules:
* Syntax
* Default exports

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde