Javascript - Module Default Exports

Introduction

You cannot export anonymous functions or classes from a module unless they are marked as default Exports using the default keyword.

You can have multiple named exports in a module but only one default export.

An ES6 module is built to pick a default export that will be the main exported value.

A single variable, function, or class can be specified as the default export of the module using the default keyword.

You can have only one value as a default export inside a module.

Using the keyword on more than one export inside the module will raise an error.

Default exports help in reducing the syntax for importing exports from a module.

export default function(a, b) { 
    return a * b; 
} 

Here, the function is exported from the module as its default.

The function does not require a name as it is the default, and the module itself represents the function.

You can assign it a name and export the function name using default.

function multiply(a, b) { 
    return a * b; 
} 

export default multiply;