To inherit properties and methods from another class in ES6, use the ________ keyword.

  • Inherits
  • Extends
  • InheritsFrom
  • ExtendsFrom
In ES6, the extends keyword is used to inherit properties and methods from another class.

What is the impact of dynamic imports on code splitting in a JavaScript application?

  • Increases modularity
  • Decreases modularity
  • Has no impact
  • Only works in Node.js
Dynamic imports in JavaScript have a positive impact on code splitting by allowing modules to be loaded on-demand. This enhances modularity, as only the necessary code is fetched when needed, reducing the initial load time of the application.

Pure functions should not modify any _________ state.

  • Local
  • External
  • Internal
  • Global
Pure functions should not have side effects, and modifying global state is considered a side effect. Therefore, they should not modify any global state.

When using arrow functions with higher-order functions like Array.prototype.map, this will refer to the ________ where the arrow function was defined.

  • Global Object
  • Callback Function
  • Scope Chain
  • Enclosing Function
Arrow functions capture the this value from their surrounding lexical scope. In the context of higher-order functions, this is crucial to understanding and avoiding potential issues.

In an AJAX call using Promises, _________ is a method used to parse the JSON response.

  • .parseJSON()
  • .toJSON()
  • .parse()
  • .json()
The correct method for parsing the JSON response in a Promises-based AJAX call is .json(). This method is specifically designed to extract and parse the JSON data from the response.

Question 2: In a large-scale application, how does the use of absolute imports in ES6 modules affect maintainability and refactoring compared to relative imports?

  • Easier refactoring, better maintainability
  • No significant impact
  • Harder refactoring, lower maintainability
  • Depends on the project structure
Using absolute imports can make refactoring more challenging, as changes to the file structure may require updating import paths throughout the codebase. This can result in lower maintainability compared to relative imports, which automatically adjust to the file's position. Consider the trade-offs based on project size and structure.

In ES6, setting "type": "______" in package.json informs Node.js to treat JavaScript files as ES modules.

  • "ES6"
  • "module"
  • "script"
  • "import"
By setting "type": "module" in package.json, Node.js is informed to treat JavaScript files as ES modules, allowing the use of import/export syntax and adhering to ES6 module behavior.

In what scenario would a WeakSet be more appropriate than a Set for managing DOM elements?

  • When managing temporary or transient DOM elements that should not prevent garbage collection.
  • WeakSet is preferred for static and permanent DOM elements to enhance performance.
  • In scenarios where strict ordering of DOM elements is crucial.
  • When managing a small number of DOM elements with known lifetimes.
WeakSet is suitable for scenarios where the collection of DOM elements may vary, and automatic garbage collection is desired.

How can you import an entire module as an object in ES6?

  • import * as myModule from './myModule';
  • import { myModule } from './myModule';
  • import myModule from './myModule';
  • import { * } from './myModule';
In ES6, you can use the import * as alias syntax to import the entire module as an object. This allows you to access all exported values through the alias object.

In a project using ES6 modules, if you need to dynamically load a module based on a user's action, which import method would you use?

  • import()
  • require()
  • import dynamic
  • import lazy
In ES6, the import() function allows dynamic loading of modules. It returns a promise that resolves to the module namespace object, allowing you to load modules conditionally or based on user actions.