Using the rest operator in function parameters collects the rest of the arguments into an ________.

  • Object
  • Array
  • Iterable
  • String
The rest operator (...) in function parameters is used to collect the rest of the arguments into an array. It allows a function to accept a variable number of arguments.

Side effects in a function include things like modifying a _________ or logging to the console.

  • Variable
  • Object
  • Array
  • State
Side effects can include modifying external state, like changing the value of a variable or an object, which goes against the principles of pure functions.

The ability to _________ values during destructuring allows for more flexible data manipulation.

  • skip
  • swap
  • default
  • mutate
The ability to set default values during destructuring provides flexibility in handling undefined or missing values, enhancing data manipulation capabilities.

What is the impact of using a pure function on the predictability and testability of code?

  • Increases unpredictability
  • Decreases testability
  • Enhances predictability
  • No impact on testability
Using pure functions in code enhances predictability by ensuring that the function's output is solely determined by its input, without relying on external state. This predictability simplifies testing, as pure functions can be easily isolated and tested independently, contributing to overall code reliability.

How does Promise chaining help in handling asynchronous operations?

  • It simplifies callback hell by allowing sequential execution of asynchronous tasks.
  • It increases the complexity of asynchronous code.
  • It only works with synchronous operations.
  • It requires additional external libraries.
Promise chaining is a technique that allows sequential execution of asynchronous tasks, making the code more readable and maintainable by avoiding callback hell.

In a scenario where you need to process a large array without blocking the event loop, how would a generator function be beneficial?

  • Allows asynchronous iteration
  • Simplifies event-driven programming
  • Enhances parallel processing
  • Efficiently manages memory
Generator functions in JavaScript allow asynchronous iteration, which is beneficial in scenarios where you need to process a large array without blocking the event loop. The yield keyword in generators facilitates asynchronous operations, enabling non-blocking code execution.

What is the primary purpose of the Symbol type in ES6?

  • Representing unique values
  • Enhancing string manipulation
  • Simplifying arithmetic operations
  • Controlling loop iterations
The primary purpose of the Symbol type in ES6 is to represent unique values. Symbols are guaranteed to be unique, and they are often used to create object properties that won't collide with properties of the same name. This uniqueness makes Symbols useful in scenarios where identifier collision is a concern.

An object is considered iterable if it implements the _________ method that returns an iterator.

  • iterate()
  • next()
  • loop()
  • iterator()
In JavaScript, an object is considered iterable if it implements the next() method, which returns an iterator. The next() method should be used to retrieve the next value in the iteration sequence.

What is the purpose of the prototype chain in JavaScript?

  • To store local variables
  • To manage asynchronous operations
  • To enable inheritance and method sharing
  • To restrict access to certain properties
The prototype chain in JavaScript is crucial for inheritance. When an object is created, it inherits properties and methods from its prototype. This chain allows objects to share functionality and promotes code reusability.

What happens if an error is thrown inside a .then() block in Promise chaining?

  • It is automatically caught by the nearest .catch() block in the chain.
  • The program crashes with an unhandled exception.
  • The error is ignored, and the program continues execution.
  • It triggers the global error handler.
If an error occurs inside a .then() block, it will be caught by the nearest .catch() block in the promise chain, preventing it from propagating further and allowing proper error handling.

ES6 introduces the __________ property in object literals for setting the prototype of the created object.

  • Prototype
  • proto
  • Object.setPrototypeOf()
  • Object.create()
In ES6, the proto property in object literals is used for setting the prototype of the created object. It provides a convenient way to establish the prototype chain for an object.

The __________ loop is used to iterate over the elements of an iterable object in JavaScript.

  • for...in
  • while
  • do...while
  • for...of
The for...of loop is specifically designed for iterating over the values of an iterable object, providing a concise and readable syntax for iteration. It simplifies the process of iterating over arrays, strings, maps, sets, and other iterable objects.