Recall & Review
beginner
What is the purpose of the
import statement in JavaScript?The
import statement is used to bring functions, objects, or values from another file or module into the current file so you can use them.Click to reveal answer
beginner
How do you import a single named value called <code>sum</code> from a module named <code>math.js</code>?You write: <br><code>import { sum } from './math.js';</code><br>This imports only the <code>sum</code> function or value from the <code>math.js</code> file.Click to reveal answer
intermediate
What is the difference between a default import and a named import?A default import brings in the main exported value from a module without curly braces, like <code>import myFunc from './file.js';</code>. Named imports require curly braces and import specific exported values, like <code>import { myFunc } from './file.js';</code>.Click to reveal answer
intermediate
How do you import all exported values from a module as a single object?You use the syntax: <br><code>import * as utils from './utils.js';</code><br>This imports everything exported from <code>utils.js</code> as properties of the <code>utils</code> object.Click to reveal answer
beginner
Can you import values from a module without specifying the file extension?In modern JavaScript environments, you usually need to include the file extension like
.js when importing modules, especially in browsers. Some tools like bundlers may allow omitting it.Click to reveal answer
Which syntax correctly imports a default export named
calculate from math.js?✗ Incorrect
Default exports are imported without curly braces.
How do you import only the named export
multiply from math.js?✗ Incorrect
Named exports require curly braces around the name.
What does this import statement do?
import * as helpers from './helpers.js';✗ Incorrect
The * as syntax imports all exports as an object.
Which is true about importing modules in JavaScript?
✗ Incorrect
You can import multiple named exports like: import { a, b } from './file.js';
What happens if you try to import a named export that does not exist in the module?
✗ Incorrect
Trying to import a non-existent named export causes a runtime error.
Explain how to import a default export and a named export from the same module.
Think about how you write import statements with and without curly braces.
You got /3 concepts.
Describe the difference between importing a single named export and importing all exports as an object.
Consider the use of curly braces and the * as syntax.
You got /3 concepts.