JavaScript Modules (import/export) Quiz
Answer 50 questions on ES modules: named vs default exports, import syntax variations, renaming, exporting functions/classes/constants, re-exporting, module scope, namespace imports, dynamic import(), browser/module loading, resolution rules, Node.js ESM/CommonJS, bundling basics, and best practices.
Question 1
What is the primary advantage of ES modules?
Question 2
Which keyword exposes bindings from a module?
Question 3
How do you import a named export foo?
Question 4
What distinguishes default exports from named exports?
Question 5
How do modules execute compared to classic scripts?
Question 6
Which attribute loads a browser script as an ES module?
Question 7
Where do module-level variables live?
Question 8
Why might you choose named exports over default?
Question 9
What happens if two modules import each other (a cycle)?
Question 10
What is a module namespace object?
Question 11
What does this module export?
export const API_URL = 'https://api.example.com'
export function fetchData() {}
export class ApiClient {}Question 12
How do you import every named export as a namespace?
import * as utils from './utils.js'
utils.log('hi')Question 13
Why is this import problematic?
import foo, { bar } from './module.cjs'Question 14
How do you rename a named export during import?
import { fetchData as request } from './api.js'
request()Question 15
How do you rename a default export during import?
import Service from './service.js'Question 16
Which statement about default and named exports is accurate?
Question 17
How do you export a value inline?
Question 18
Which statement re-exports a binding without creating a local variable?
export { formatDate } from './date-utils.js'Question 19
What does export * from "./module.js" accomplish?
Question 20
How do you import both the default export and named exports in one statement?
import Foo, { bar, baz } from './module.js'Question 21
What does module scope guarantee?
Question 22
What does this namespace import log?
import * as math from './math.js'
console.log(Object.keys(math))Question 23
How can you lazy-load a module only when a feature is needed?
async function loadFeature() {
const module = await import('./feature.js')
return module.init()
}Question 24
What does this module demonstrate about shared state?
let counter = 0
export function increment() {
counter += 1
return counter
}Question 25
Why should imported bindings be treated as read-only?
Question 26
What is tree shaking?
Question 27
What does globalThis._importMeta_.url provide?
console.log(globalThis._importMeta_.url)Question 28
How do import assertions help load JSON modules?
Question 29
What does this code log when multiple files call increment()?
import { increment } from './counter.js'
console.log(increment())Question 30
Why should circular dependencies be minimized?
Question 31
What does this import path imply in the browser?
import { render } from '../components/render.js'Question 32
How does Node.js resolve ES modules by default?
Question 33
What does package.json "type": "module" do?
Question 34
How do you import CommonJS modules inside an ES module in Node?
const pkg = await import('node:fs')
const fs = pkg.default || pkgQuestion 35
What are package imports (e.g., "#utils")?
Question 36
What does this dynamic import in Node accomplish?
const { readFile } = await import('node:fs/promises')Question 37
What role do bundlers play in module-based projects?
Question 38
Which statement about code splitting is true?
Question 39
How can environment-specific modules be selected?
Question 40
Why is explicit file extension usage recommended in ESM?
Question 41
How do you import CommonJS modules from ESM in Node if you need synchronous semantics?
Question 42
What is the primary difference between CommonJS and ES modules?
Question 43
Why should module specifiers avoid file-system specific assumptions?
Question 44
What is a common pattern for organizing exports in large projects?
Question 45
Why is using consistent file extensions important when mixing ESM and CJS in Node?
Question 46
Why should you avoid mixing default exports with too many named exports in the same file?
Question 47
Which best practice helps prevent accidental default export renames?
Question 48
Why should environment-specific configuration be isolated into separate modules?
Question 49
What is a recommended strategy for module organization in large apps?
Question 50
Which best practice improves readability when importing many bindings?
