In what scenario would a callback be more appropriate than a Promise?

  • When dealing with simple and sequential asynchronous tasks.
  • Callbacks are never more appropriate than Promises.
  • In complex situations where multiple asynchronous tasks depend on each other.
  • Promises are always preferred over callbacks.
Callbacks are suitable for straightforward, sequential tasks where the asynchronous nature is not overly complex. Promises shine in scenarios involving more complex asynchronous workflows, providing better control and readability. Understanding the use cases for callbacks versus Promises is essential for choosing the right approach in different asynchronous programming scenarios.

In ES6, a function parameter's default value can be another function's _________.

  • name
  • return value
  • parameters
  • scope
In ES6, a function parameter's default value can be another function's return value. This allows for dynamic default values based on the execution of the provided function.

When using a for...of loop, what keyword is used to access the current item in the collection?

  • for
  • in
  • of
  • each
The for...of loop uses the "of" keyword to iterate over the values of an iterable object, providing a cleaner syntax compared to the for...in loop.

Is it possible to rename variables while destructuring an object or array?

  • Yes, by using the as keyword
  • No, renaming is not supported in destructuring
  • Yes, by using the rename keyword
  • Yes, by providing an alias after a colon
Yes, it is possible to rename variables during destructuring in JavaScript. The as keyword is used to provide an alias for the variable, allowing you to use a different name than the original property or array element.

What is a potential downside of using higher-order functions excessively in JavaScript?

  • Increased complexity and potential for code readability issues
  • Improved code maintainability and easier debugging
  • Enhanced performance due to optimized function calls
  • Reduced flexibility in handling different use cases
Excessive use of higher-order functions can lead to increased code complexity and potential readability issues, as functions become deeply nested and harder to follow.

What is the key feature of enhanced object literals in ES6 that allows properties to be set more concisely?

  • Shorthand property notation
  • Computed property names
  • Method shorthand notation
  • Default parameter values
In enhanced object literals, shorthand property notation allows concise property assignment. This means you can omit the repetition of the property name if it matches the variable name. This enhances code readability.

In an application dealing with an array of user objects, which higher-order function would be best for filtering users based on specific criteria?

  • map
  • filter
  • reduce
  • forEach
The correct option is filter. filter is specifically designed for filtering elements in an array based on a given criteria. It creates a new array with only the elements that satisfy the provided function.

How does tree shaking contribute to the final bundle size in a JavaScript project?

  • Increases the bundle size
  • Has no impact on the bundle size
  • Decreases the bundle size by removing unused code
  • Only affects the bundle size for server-side code
Tree shaking significantly reduces the final bundle size by identifying and excluding unused or dead code. It helps in delivering a more optimized and lightweight application to end-users. Developers can achieve a smaller bundle size, leading to faster load times and improved overall performance, especially in resource-intensive web applications.

What is the purpose of the map method in JavaScript arrays?

  • Iterates over each element, allowing you to modify them and returns a new array with the results.
  • Removes elements that do not satisfy a certain condition and returns a new array.
  • Reduces the array to a single value based on a provided function.
  • Returns the first element that satisfies a given condition.
The map method is used to iterate over each element in the array, apply a function to each element, and return a new array with the results. It doesn't modify the original array. This is commonly used for transforming data in arrays.

The spread operator is used to ________ elements of an iterable into individual elements.

  • Combine
  • Separate
  • Flatten
  • Merge
The spread operator (...) is used to separate the elements of an iterable, like an array, into individual elements. This is often used to spread elements into a new array or function arguments.