Recall & Review
beginner
What is the main purpose of ES Modules in Node.js?
ES Modules allow you to organize and reuse code by importing and exporting functions, objects, or values between files in a clear and standardized way.
Click to reveal answer
beginner
How do you export a single function as the default export in an ES Module?
Use
export default functionName; to export a single function as the default export from a module.Click to reveal answer
beginner
What is the syntax to import a default export from another module?Use <code>import anyName from './module.js';</code> where <code>anyName</code> is your chosen name for the default export.Click to reveal answer
intermediate
How do you export multiple named values from a module?
Use <code>export const name1 = value1;</code> or <code>export { name1, name2 };</code> to export multiple named values.Click to reveal answer
intermediate
How can you import multiple named exports from a module?Use <code>import { name1, name2 } from './module.js';</code> to import specific named exports.Click to reveal answer
Which keyword is used to export a default value in ES Modules?
✗ Incorrect
The
export default keyword exports a single default value from a module.How do you import a named export called
calculate from a module?✗ Incorrect
Named exports are imported using curly braces:
import { calculate } from './module.js';.What file extension should you use for ES Modules in Node.js by default?
✗ Incorrect
The
.mjs extension explicitly marks a file as an ES Module in Node.js.Which statement is true about mixing CommonJS and ES Modules in Node.js?
✗ Incorrect
ES Modules can import CommonJS modules, but CommonJS modules cannot directly import ES Modules without special handling.
How do you export a variable named
count as a named export?✗ Incorrect
Use
export { count }; to export count as a named export.Explain how to export and import both default and named values using ES Modules in Node.js.
Think about how you share one main thing versus multiple things from a file.
You got /4 concepts.
Describe the difference between ES Modules and CommonJS modules in Node.js and how they interact.
Consider the keywords and compatibility between the two module systems.
You got /4 concepts.