ES6 Modules use the import and export keywords, whereas CommonJS modules use require and module.exports for _________.

  • Dependency Injection
  • Module Loading
  • Code Splitting
  • Module Definition
ES6 Modules use the import and export keywords for module management, while CommonJS uses require and module.exports. Understanding these differences is crucial when working with different module systems in JavaScript.

In ES6, default parameters can be used to simulate named parameters in a function.

  • Variables
  • Arguments
  • Constants
  • Expressions
Default parameters in ES6 allow you to assign default values to function parameters. When a value is not provided during the function call, the default value is used. This behavior is similar to having named parameters in functions. The correct option here is "Arguments," representing the parameters in a function.

Is it possible to break out of a for...of loop prematurely, and if so, how?

  • Yes, you can use the break statement to exit the for...of loop prematurely.
  • No, for...of loops do not support the break statement.
  • Yes, but it requires using a special flag.
  • No, for...of loops always iterate over the entire iterable.
Yes, it is possible to break out of a for...of loop prematurely by using the break statement. This allows you to exit the loop before it has completed its iteration over the entire iterable. The break statement is a common control flow mechanism in loops.

How does the reduce method's accumulator work in each iteration of the array?

  • It accumulates the values from left to right
  • It accumulates the values from right to left
  • It accumulates the values randomly
  • It accumulates the values based on a specified condition
The accumulator in the reduce method accumulates values from left to right in each iteration, combining them based on the provided callback function. This behavior is crucial for performing various operations on an array, such as summing or concatenating elements.

How do you handle errors when using Promises with AJAX requests?

  • try-catch block
  • .catch() method
  • if-else statements
  • Error callback function
Errors in Promises can be handled using the .catch() method, which allows you to specify a callback function for error handling. This enhances the robustness of the code by providing a centralized way to deal with errors in asynchronous operations.

What happens when undefined is passed to a function with a default parameter?

  • The default parameter is used
  • An error is thrown
  • The function assigns a default value
  • It takes the value 'undefined'
When 'undefined' is passed, the default parameter is used. Explanation should cover how default parameters handle 'undefined' and when they come into play.

Which method is used to handle errors in a JavaScript Promise?

  • catch()
  • reject()
  • error()
  • handleError()
The catch() method is used to handle errors in a JavaScript Promise. It allows you to specify a callback function that will be executed if the promise is rejected. Option A is correct because it represents the correct method for handling errors in promises.

Can getter and setter functions be defined within ES6 object literals?

  • Yes, both getter and setter functions can be defined.
  • No, only getter functions are allowed.
  • No, only setter functions are allowed.
  • No, neither getter nor setter functions are allowed.
In ES6 object literals, both getter and setter functions can be defined using the concise method syntax. This feature allows developers to encapsulate access to object properties, providing a cleaner and more controlled way to retrieve and set values. Using getter and setter functions within object literals enhances the encapsulation of data and promotes a more modular code structure.

To optimize tree shaking, developers should avoid _______ side effects in their module code.

  • Pure
  • Impure
  • Global
  • Conditional
Tree shaking relies on the ability to analyze and remove dead code. Side effects in module code, especially impure ones, can hinder the accuracy of tree shaking. Developers are encouraged to write "pure" functions and modules, which have no side effects and make tree shaking more effective.

Arrow functions do not have their own this keyword; instead, they ________ the this value from the enclosing execution context.

  • Absorb
  • Inherit
  • Borrow
  • Capture
Arrow functions in JavaScript do not have their own this context. Instead, they inherit the this value from the enclosing execution context. This behavior is different from regular functions, which have their own this binding.