JavaScript Modules Default exports

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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;
}


Got any JavaScript Question?