Syntax

JavaScript Import a Module Syntax

In JavaScript, import a module: imports exports from another module — import { add } from "./math.js";

Quick Answer

Syntax
import { add } from "./math.js";
JavaScriptSyntax

Import a Module

Code example
import { add } from "./math.js";

Imports exports from another module.

Learn More

How to import a module in JavaScript

  1. Open your JavaScript file or editor.
  2. Copy the example, then replace its sample names and values for your code.

JavaScript Import a Module Syntax

Use import { add } from "./math.js";.

Related Syntax References

Frequently asked questions

What is the JavaScript syntax for import a module?

Use this pattern: import { add } from "./math.js";

Can I copy this JavaScript code example?

Yes. Use Copy code and adapt the example to your program.

Is this JavaScript syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify