Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Import

You can import modules into a file in two ways, depending on whether they are named exports or default exports.

Named exports are imported using curly braces, while default exports are imported without them.

Import from named exports

Import the named exports from the person.js file.

import { name, age } from “./person.js”;

Import from default exports

Import the default export from the message.js file.

import message from “./message.js”;

Note

Modules only work with the HTTP(s) protocol. A web page opened using the file:// protocol cannot use import or export.