jskatas.org Continuously Learn JavaScript. Your Way.

Modules: import statement

Use import to import functions that have been exported somewhere else.

use import to import functions that have been exported (somewhere else)

the import statement

is only allowed on the root level
// Try to comment this out, it will yell at you! { // import assert from 'assert'; }
import an entire module using import <name> from "<moduleName>"
//: {"jskatas": {"runnerOptions": {"runGivenCodeOnly": true, "type": "module"}}} import assert from 'https://jskatas.org/assert.esm.js'; const expectedType = '???'; assert.equal(typeof assert, expectedType);

import members

import a single member, using import {<memberName>} from "module"
//: {"jskatas": {"runnerOptions": {"runGivenCodeOnly": true, "type": "module"}}} import assert from 'https://jskatas.org/assert.esm.js'; import {equal} from 'https://jskatas.org/assert.esm.js'; assert.strictEqual(equal, assert.equal);

separate multiple members with a comma

deepEqual from the assert module
//: {"jskatas": {"runnerOptions": {"runGivenCodeOnly": true, "type": "module"}}} import assert from 'https://jskatas.org/assert.esm.js'; import {equal, deepEqual} from 'https://jskatas.org/assert.esm.js'; assert.strictEqual(equal, assert.equal); assert.strictEqual(deepEqual, assert.deepEqual);

alias imports

using member as alias as memberName
//: {"jskatas": {"runnerOptions": {"runGivenCodeOnly": true, "type": "module"}}} import assert from 'https://jskatas.org/assert.esm.js'; import {equal as myEqual} from 'https://jskatas.org/assert.esm.js'; assert.strictEqual(myEqual, assert.equal);
rename the default export of a module, using default as alias as memberName
//: {"jskatas": {"runnerOptions": {"runGivenCodeOnly": true, "type": "module"}}} import assert from 'https://jskatas.org/assert.esm.js'; import {default as myAssert} from 'https://jskatas.org/assert.esm.js'; assert.strictEqual(myAssert, assert);

Difficulty Level

BEGINNER

Stats

6 tests to solve