JavaScript modules and imports

How do you write the import?

Examples

Worked example

Input
math.js exports add; another file needs it under the name sum.
Expected output
import { add as sum } from './math.js';

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

The real export is named add. The as clause gives it a different name in the importing file.

Back to the lesson