JavaScript: Import

By Xah Lee. Date: .

New in JS2015.

There 2 kind of export by JavaScript modules.

default export
The module marks one single object for export. This object is not named.

You give it a name when you import it.

named export
The module marks several names (identifers. Each can be any value type).

When you import, you explicitly list them for import.

Import Syntax for Default Export

import newName from modulePath;
This import a default exported OBJECT at modulePath and name this OBJECT newName in your source code.

The newName can be anything you choose.

Import Syntax for Named Export

import { name1 , name2 … } from modulePath;
Import into your file a list of exported names. (Each of the name must be explicited exported by the module.)
import { name1 as new1 … } from modulePath;
Import into your file a list of exported names with new alias. Your code access the imported symbols by their new name, e.g. new1
import * as newName from modulePath;
get all exported names from modulePath, attach to newName as properties.

Load Module

This will just load module:

import modulePath;

JavaScript: Import/Export

JavaScript in Depth

JavaScript in Depth

Basic Syntax

Value Types




Object and Inheritance




Iterable 🌟