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 WeakSet, the existence of an object in the set does not prevent it from being ________ by the garbage collector.

  • Referenced
  • Mutated
  • Duplicate
  • Garbage collected
The objects in a WeakSet are weakly held, similar to WeakMap, allowing them to be garbage collected even if they are present in the WeakSet. This is useful for managing sets of objects when their presence should not hinder garbage collection.

How do higher-order functions contribute to a functional programming style in JavaScript?

  • Enable the creation of more concise and expressive code by treating functions as first-class citizens
  • Allow functions to be passed as arguments and returned as values, facilitating the use of function composition
  • Provide a way to encapsulate and abstract behavior, promoting modularity and reusability
  • Enable the creation of custom control structures like map, filter, and reduce
Higher-order functions in JavaScript contribute to a functional programming style by allowing functions to be passed as arguments and returned as values, enabling function composition and facilitating modularity and reusability.