Explore key concepts and features of asynchronous programming in…
Start QuizExplore underrated JavaScript libraries that offer powerful solutions for…
Start QuizExplore how pnpm 10 enhances package installation security and…
Start QuizExplore how JavaScript classes relate to prototypes, constructor functions,…
Start QuizDiscover the proven patterns and practical habits that distinguish…
Start QuizChallenge your understanding of JavaScript function definitions, syntax, and…
Start QuizSharpen your understanding of JavaScript objects with these easy…
Start QuizExplore the basics of JavaScript loops with these straightforward…
Start QuizExplore easy questions covering fundamental JavaScript concepts, suitable for…
Start QuizExplore the basics of the JavaScript Event Loop, including…
Start QuizChallenge your JavaScript fundamentals with 15 essential interview questions…
Start QuizExplore essential concepts for handling dependencies across multi-package JavaScript…
Start QuizChallenge your understanding of fundamental JavaScript concepts with these…
Start QuizExplore the history and evolution of JavaScript, from its…
Start QuizEnhance your understanding of JavaScript with this beginner-friendly quiz…
Start QuizTest your understanding of common internet troubleshooting scenarios and…
Start QuizTest your knowledge of ES6 (ECMAScript 2015) features with…
Start QuizTest your understanding of key JavaScript topics with these…
Start QuizTest your knowledge with these commonly asked JavaScript interview…
Start QuizTest your knowledge of Observables in JavaScript, including their…
Start QuizTest your knowledge of essential JavaScript developer tips and…
Start QuizTest your knowledge of JavaScript ES6 features with this…
Start QuizTest your understanding of core JavaScript concepts relevant to…
Start QuizTest your understanding of Node.js fundamentals with this quiz…
Start QuizAssess your understanding of JavaScript modules, including import/export syntax, module advantages, scope, and related concepts essential in frontend development.
This quiz contains 10 questions. Below is a complete reference of all questions, answer choices, and correct answers. You can use this section to review after taking the interactive quiz above.
Which statement correctly imports a named export 'calculate' from a file called 'math.js'?
Correct answer: import { calculate } from './math.js';
Explanation: The correct syntax for importing a named export is using curly braces. Option B is the default import syntax and only works if 'calculate' is exported as default. Option C is invalid syntax. Option D uses CommonJS syntax, not ES modules.
Which keyword is used to define a default export in a JavaScript module?
Correct answer: default
Explanation: The 'default' keyword is used with 'export' to designate the default export. The other options are not recognized JavaScript keywords for exporting modules.
How does module-level scope in JavaScript modules differ from script-level scope?
Correct answer: Variables declared in a module are not added to the global scope.
Explanation: Module scope means variables declared in a module are private to that module by default. Option B is incorrect because variables are not global. Option C is false; modules do not automatically inherit globals. Option D wrongly claims only functions are restricted.
What is a main benefit of using JavaScript modules in frontend development?
Correct answer: They help organize code and reduce naming conflicts.
Explanation: Modules enable better code organization and encapsulation, reducing conflicts. Compression requires separate tools. Load times aren't guaranteed by modules alone. Syntax errors still need fixing by the developer.
Which statement re-exports all exports from 'utils.js' in a new module?
Correct answer: export * from './utils.js';
Explanation: 'export * from' syntax re-exports everything. Option B is for default exports and invalid here. Option C is an import statement, not export. Option D uses CommonJS, not ES modules.
How do you import all named exports from 'helpers.js' as a single object called 'helpers'?
Correct answer: import * as helpers from './helpers.js';
Explanation: 'import * as helpers' gathers all named exports under the 'helpers' namespace. Option B imports a default export, not all exports. Option C is invalid syntax. Option D uses CommonJS, which is not ES module syntax.
What happens if you import a module solely for its side effects, without importing any bindings?
Correct answer: import './module.js'; runs the module's top-level code.
Explanation: Importing a module without bindings still executes its top-level code. Option B is false; the code does run. Option C is incorrect; imports can be just for side effects. Option D is wrong; this is valid syntax in ES modules.
When importing a local module in a browser ES module environment, what file extension is required?
Correct answer: .js
Explanation: Browsers generally require the '.js' extension for module imports. '.module' is not recognized. '.mjs' is used in Node.js but less common in browsers. Omitting the extension usually results in an error.
Which statement is true of exporting multiple functions from a JavaScript module?
Correct answer: You can use multiple named exports in a module.
Explanation: JavaScript modules support multiple named exports, making them flexible. The other options are incorrect: there is no one-export or one-function-per-module limitation, and functions do not have to be default exports.
How do you dynamically import a module in JavaScript at runtime?
Correct answer: import('./myModule.js')
Explanation: The dynamic import syntax uses 'import()' as a function that returns a promise. 'require' is not valid in browser ES modules. The third option uses static import syntax, and the fourth is an export statement.