How does chaining array methods like map and filter affect performance?

  • Negatively impacts performance due to multiple iterations
  • Positively impacts performance by optimizing the code
  • No significant impact on performance
  • Only affects readability, not performance
Chaining array methods like map and filter can negatively impact performance due to multiple iterations. Each method creates a new array, and chaining them leads to intermediate arrays, causing additional iterations. This can be inefficient, especially for large datasets.

Imagine processing a shopping cart array to calculate the total price. Which method would efficiently achieve this?

  • map
  • reduce
  • filter
  • forEach
The most efficient method for calculating the total price in a shopping cart array is reduce. The reduce method iterates over each element of the array and accumulates a result. In this case, it can sum up the prices to provide the total cost.

What is a practical use case of currying in JavaScript?

  • Simplifying function composition
  • Handling asynchronous operations
  • Memoization
  • Event handling in UI
Currying simplifies function composition by breaking down functions into smaller, reusable units. This is useful for creating more modular and maintainable code, especially in functional programming paradigms.

How can dynamic imports be used to implement feature flags in a large-scale web application?

  • Load all features during the initial page load.
  • Use dynamic imports to conditionally load features based on feature flags.
  • Hardcode feature flags directly in the application code.
  • Use static imports to include all features in the main bundle.
Dynamic imports enable the implementation of feature flags by allowing the loading of features based on runtime conditions. This flexibility helps in enabling or disabling specific features without changing the core codebase.

Can a default export be imported with any name?

  • Yes
  • No
  • Only in certain cases
  • Depends on the file structure
In ES6, a default export can be imported with any name. The imported name is not dictated by the exporting module. It allows flexibility in naming while importing, making it more convenient.

When using Symbols for object properties, they are not included in __________ enumerations.

  • for...in'
  • forEach'
  • Object.keys()'
  • Object.getOwnPropertySymbols()'
Object properties with Symbols as keys are not included in for...in enumerations. To get all property keys (including Symbols), you can use Object.getOwnPropertySymbols() in addition to other methods. Example: const symbols = Object.getOwnPropertySymbols(myObject);

Destructuring an object within a _________ allows for directly mapping object properties to function parameters.

  • Callback function
  • Template literal
  • Arrow function
  • Promise
Destructuring an object within an "Arrow function" allows for directly mapping object properties to function parameters. Arrow functions provide a concise syntax, and when combined with destructuring, you can streamline the mapping of object properties to function parameters.

To check if a Map contains a certain key, use the _________ method.

  • hasKey
  • checkKey
  • has
  • includes
The correct method is has. In JavaScript, the Map object has a has method that returns a boolean indicating whether the map contains a specified key. Example: myMap.has('key').

In a function that accepts a variable number of arguments and needs to pass them to another function, how would the rest operator be applied?

  • Declare the function parameters using the rest operator, e.g., (...args)
  • Use the spread operator to pass arguments to the function
  • Define the function with a fixed number of parameters
  • Use the arguments object within the function
The rest operator (...) is employed in function parameters to collect a variable number of arguments into an array. For example, (...args) allows the function to accept any number of arguments and access them within an array named args.

In advanced functional composition, ________ functions can be used to enhance readability.

  • Pure
  • Higher-order
  • Impure
  • Recursive
In advanced functional composition, higher-order functions can be used to enhance readability. Higher-order functions are functions that can take other functions as arguments or return them as results, providing a powerful tool for composing complex behavior while maintaining code clarity.