(Full Stack JavaScript) ES6 Modules Knowledge Assessment Q & S 2024, Exams of Programming Languages

(Full Stack JavaScript) ES6 Modules Knowledge Assessment Q & S 2024(Full Stack JavaScript) ES6 Modules Knowledge Assessment Q & S 2024(Full Stack JavaScript) ES6 Modules Knowledge Assessment Q & S 2024(Full Stack JavaScript) ES6 Modules Knowledge Assessment Q & S 2024(Full Stack JavaScript) ES6 Modules Knowledge Assessment Q & S 2024

Typology: Exams

2023/2024

Available from 07/05/2024

emilio-clemente-2
emilio-clemente-2 🇺🇸

2

(2)

356 documents

1 / 21

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Full Stack JavaScript
ES6 Modules
Knowledge Assessment
Q & S
2024
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download (Full Stack JavaScript) ES6 Modules Knowledge Assessment Q & S 2024 and more Exams Programming Languages in PDF only on Docsity!

Full Stack JavaScript

ES6 Modules

Knowledge Assessment

Q & S

  1. Which of the following is the correct way to import the default export from a module named mathUtils.js? a) import { default as mathUtils } from './mathUtils.js'; b) import as mathUtils from './mathUtils.js'; c) import mathUtils from './mathUtils.js'; d) import { mathUtils } from './mathUtils.js';

Answer: c) import mathUtils from './mathUtils.js';

Rationale: Default exports are imported without curly braces.

  1. Given a module geometry.js with the following exports, which statement correctly imports only the calculateArea function?

    export function calculateArea(radius) { return Math.PI radius radius; } export function calculatePerimeter(radius) { return 2 Math.PI radius; } 
  2. Which statement correctly re-exports all bindings from a module named utils.js? a) export default from './utils.js'; b) export from './utils.js'; c) import from './utils.js'; d) export { default as } from './utils.js';

Answer: b) export from './utils.js';

Rationale: export is used to re-export all bindings from another module.

  1. What will be the output if the following code is executed?
    // module1.js export let counter = 1; // main.js import { counter } from './module1.js'; counter += 1; console.log(counter); 

a) 1 b) 2 c) NaN d) SyntaxError

Answer: d) SyntaxError

Rationale: counter is a read-only binding when imported.

Fill-in-the-Blank Questions

  1. The syntax for importing all named exports from a module helpers.js and assigning them an alias helpers is ________.

Answer: import as helpers from './helpers.js';

Rationale: The syntax as alias is used for importing all named exports.

  1. In ES6, a module that does not explicitly state anything about exports is said to be in ________ mode by default.

Answer: strict

Rationale: Default exports are imported without curly braces using an alias.

True/False Questions

  1. You can mix named exports and default exports within the same module.

Answer: True

Rationale: ES6 modules allow both named exports and a single default export within the same module.

  1. All imports in ES6 modules are hoisted to the top of the module.

Answer: True

Rationale: Imports are hoisted, meaning they are moved to the top of the file during compilation.

  1. You cannot use dynamic expressions in import statements.

Answer: True

Rationale: Import statements cannot use dynamic expressions and must use string literals.

  1. Once a module is imported, its internal state can be modified directly by other modules.

Answer: False

Rationale: Imported bindings are read-only views of the exports from the imported module.

  1. ES6 modules are automatically wrapped in strict mode.

Answer: True

Rationale: ES6 modules are implicitly in strict mode, which enforces stricter parsing and error handling.

  1. A single module cannot have multiple default exports.

Answer: True

Rationale: Dynamic import() is a function that can be used to import modules conditionally.

  1. An ES6 module can be used to encapsulate both functions and classes to promote modular code structure.

Answer: True

Rationale: ES6 modules are designed to encapsulate code, including functions and classes for modularity. Multiple Choice: Which statement about ES6 Modules is true? A) They have a global scope. B) They are always loaded asynchronously. C) They support both named and default exports. D) They cannot be imported into other modules.

Correct Answer: C) They support both named and default exports.

Rationale: ES6 Modules allow developers to export multiple values from a single module using named exports and a single default export.

Fill-in-the-Blank: To import a default export from a module in ES6, you use the _ keyword.

Correct Answer: import

Rationale: When importing a default export from an ES6 module, the import keyword is used followed by the module path and the name for the default export in curly braces. True/False: In ES6 Modules, all code is executed in global scope.

Correct Answer: False

Rationale: ES6 Modules have their scope, which helps in avoiding pollution of the global scope by encapsulating code within modules. Multiple Choice: What is the purpose of the export default syntax in ES6 Modules? A) To export multiple named exports B) To define the default export for a module C) To prevent other modules from importing the current module

Multiple Choice: Which keyword is used to export a named export in an ES6 Module? A) import B) export C) require D) module

Correct Answer: B) export

Rationale: The export keyword is used to export named exports from an ES6 Module, making them accessible to other modules. Fill-in-the-Blank: ES6 Modules use _ to control what is visible outside the module.

Correct Answer: exports

Rationale: In ES6 Modules, the exports object is used to define what parts of the module are accessible to other modules when imported. True/False:

ES6 Modules are supported in all major modern browsers without the need for transpilation.

Correct Answer: True

Rationale: ES6 Modules are natively supported in modern browsers, allowing developers to use them without the need for transpilation tools like Babel. Multiple Choice: Which of the following is an advantage of using ES6 Modules? A) Reduced code maintainability B) Global namespace pollution C) Improved code organization D) Limited reusability

Correct Answer: C) Improved code organization

Rationale: ES6 Modules help in organizing code into smaller, reusable components, improving overall code organization and maintainability. Fill-in-the-Blank: Default exports in ES6 Modules can be imported using any name by using the _ keyword.

Rationale: ES6 Modules are loaded asynchronously, improving page load performance by fetching modules in parallel. Fill-in-the-Blank: The import as module syntax in ES6 Modules is used to _.

Correct Answer: import an entire module namespace

Rationale: The import as module syntax in ES6 Modules imports the entire module namespace, allowing access to all exports from the module. True/False: ES6 Modules can have both a named export and a default export in the same module.

Correct Answer: True

Rationale: ES6 Modules allow for a combination of named exports and a default export within the same module, providing flexibility in exporting functionality.

Multiple Choice: Which statement correctly imports a single export named myExport from a module? A) import { myExport } from 'module'; B) import myExport from 'module'; C) import as myExport from 'module'; D) import 'module' as myExport;

Correct Answer: A

Rationale: Option A uses the correct syntax for importing a named export from a module, which is enclosed in curly braces. True/False: The statement import as myModule from 'module'; imports all exports from 'module' as a single object named myModule.

Answer: True

Rationale: The import as syntax is used to import all named exports from a module as properties of a single object. Fill-in-the-Blank: To dynamically import a module, the _______ function can be used.

Answer: import()

Rationale: The import() function allows for dynamic importing of modules, which can be useful for code splitting and lazy loading. Multiple Choice: What is the purpose of the default keyword in an export statement? A) To specify a fallback export

C) export default myFunc1, myFunc2; D) export let myLet = 'value';

Correct Answer: C

Rationale: Option C is incorrect because the default keyword can only be used with a single value, not multiple values. True/False: The export keyword can be used inside a function to export local variables.

Answer: False

Rationale: The export keyword cannot be used inside functions; it is used at the top level of a module to export variables, functions, or classes. Fill-in-the-Blank: To import only a subset of exports from a module, use the syntax import { ____ } from 'module'; and replace the blanks with the desired exports.

Answer: export names

Rationale: The curly braces are used to list the specific named exports that should be imported from the module. Multiple Choice: What does the export default statement do in a module? A) It exports the module's interface B) It exports a single value as the default export C) It sets the default values for all exports D) It exports all values as named exports

Correct Answer: B

Rationale: The export default statement is used to define a single value that will be exported as the default from the module. True/False: A module can have multiple default exports.

Answer: False

Rationale: A module can only have one default export, which is the value that will be imported when the import statement does not use curly braces. Fill-in-the-Blank: The syntax to re-export all exports from a module is export from '____';.

Answer: module

Rationale: The export from 'module'; syntax is used to re-export all named exports from the specified module. Multiple Choice: How can you provide an alias for a default export when importing it? A) import { default as myAlias } from 'module'; B) import myAlias from 'module'; C) import as myAlias from 'module'; D) import myAlias, { default } from 'module';

Correct Answer: B

Rationale: Option B is the correct way to import a default export and give it an alias; the other options are not valid syntax for this purpose.