1. What is the purpose of the 'export' keyword in ES6 modules?
A) To import functions from another module
B) To export functions or values from a module
C) To define a module
D) To execute a module
Show Explanation
2. What does the 'import' keyword do in ES6 modules?
A) It imports functions or values from another module
B) It exports functions from the current module
C) It creates a new module
D) It initializes a module
Show Explanation
3. What is the main difference between CommonJS and ES6 modules?
A) CommonJS is synchronous, ES6 is asynchronous
B) CommonJS uses require and module.exports, ES6 uses import and export
C) ES6 modules are not compatible with Node.js
D) CommonJS does not support exports
Show Explanation
4. What is a default export in ES6 modules?
A) A module can export a single value or object
B) A module can export multiple values
C) A module cannot have default exports
D) Default exports are only for classes
Show Explanation
5. What are named exports in ES6 modules?
A) A single value exported from a module
B) Multiple values exported with specific names
C) Only functions can be named exports
D) Named exports cannot be imported
Show Explanation
6. How do ES6 modules differ from CommonJS modules in terms of loading?
A) ES6 modules are asynchronous; CommonJS modules are synchronous
B) Both are synchronous
C) Both are asynchronous
D) CommonJS modules can be used in the browser
Show Explanation
7. Can you have both named exports and a default export in the same module?
A) Yes, you can
B) No, you cannot
C) Only named exports are allowed
D) Only default exports are allowed
Show Explanation
8. What can happen with circular dependencies in ES6 modules?
A) They will work without any issues
B) They may lead to undefined values
C) They will throw an error
D) They are not allowed in ES6 modules
Show Explanation
9. How do you import a default export in ES6 modules?
A) import { value } from 'module'
B) import * from 'module'
C) import value from 'module'
D) import [value] from 'module'
Show Explanation
10. How do you import named exports from a module?
A) import { value1, value2 } from 'module'
B) import value1, value2 from 'module'
C) import [value1, value2] from 'module'
D) import * from 'module'
Show Explanation
11. How can you load ES6 modules in your JavaScript code?
A) Using the 'import' statement
B) Using the 'require' statement
C) Using the 'include' statement
D) Using the 'load' statement
Show Explanation
12. What is a module in JavaScript?
A) A global variable
B) A self-contained block of code that can export and import
C) A collection of functions only
D) A type of object
Show Explanation
13. How do you define a default export in an ES6 module?
A) export default { value }
B) export default functionName()
C) module.exports = functionName
D) exports.default = functionName
Show Explanation
14. Why are named exports called 'named' exports?
A) They must be imported using their exact names
B) They are always imported as default
C) They can have any name during import
D) They are optional
Show Explanation
15. What does the export * from 'module' syntax do?
A) It imports all exports
B) It re-exports all exports from the specified module
C) It exports only the default export
D) It exports a single named export
Show Explanation
16. Why are modules important in JavaScript?
A) They improve code organization and reuse
B) They increase execution speed
C) They prevent all global variables
D) They reduce the need for functions
Show Explanation
17. What file extension do ES6 modules typically use?
A) .mjs
B) .js
C) .module
D) .es6
Show Explanation
18. How can you include an ES6 module in an HTML file?
A)
B)
C)
D)
Show Explanation
19. Why might developers use a bundler with ES6 modules?
A) To write code without modules
B) To combine multiple modules into a single file
C) To create global variables
D) To avoid using any modules
Show Explanation
20. What does the .mjs file extension signify?
A) It is a CommonJS module
B) It is an ES6 module
C) It is a script file
D) It is a CSS file
Show Explanation