Which of the following is a built-in higher-order function in JavaScript?

  • map()
  • add()
  • concat()
  • subtract()
The map() function in JavaScript is a built-in higher-order function that is commonly used to transform elements of an array. It takes a function as an argument and applies it to each element of the array.

To pause and resume a generator function, the _________ keyword is used within the function body.

  • yield
  • await
  • pause
  • resume
In a generator function, the yield keyword is used to pause and resume the function's execution. It allows the generator to produce a sequence of values over time. The other options are not relevant to the purpose of pausing and resuming a generator.

What is a common pitfall when chaining multiple asynchronous operations using Promises?

  • Not handling errors within each promise's chain.
  • Mixing Promises with Callbacks.
  • Using async/await inside a promise chain.
  • Chaining promises without returning a new promise.
One common pitfall is forgetting to return a new promise when chaining promises. If a promise is not returned from each .then() callback, subsequent promises won't wait for the asynchronous operation to complete, potentially leading to unexpected behavior.

In functional programming, what is the recommended way to handle functions with side effects?

  • Embrace side effects
  • Minimize side effects
  • Avoid functions altogether
  • Encourage side effect propagation
In functional programming, it is recommended to minimize side effects. While it may be challenging to eliminate them entirely, minimizing side effects helps maintain the purity of functions and promotes a more declarative and predictable coding style. This approach contributes to better code maintainability and understandability.

What syntax is used to handle the promise returned by a dynamic import?

  • await import('module')
  • import('module').then()
  • dynamicImport('module')
  • import('module').catch()
The correct syntax to handle the promise returned by a dynamic import is import('module').then(). You use the then method to perform actions once the module has been successfully loaded. The catch method can be used for error handling if the dynamic import fails.

What is the primary benefit of using Promises in AJAX calls over traditional callback functions?

  • Asynchronous handling
  • Synchronous handling
  • Simplicity
  • Compatibility
Promises provide a cleaner and more readable way to handle asynchronous operations, making code more maintainable and avoiding callback hell. They allow better error handling and chaining of multiple asynchronous operations.

Is it possible to declare a variable with let or const in a for-loop and access it outside of the loop?

  • Yes, you can access it outside the loop
  • No, it's not accessible outside the loop
  • Only let variables are accessible
  • Only const variables are accessible
Variables declared with let or const in a for-loop are accessible outside of the loop in which they are declared. They have block scope, which means they are confined to the nearest enclosing curly braces, allowing them to be accessed outside the loop.

A common use case for currying is to create more _________ versions of existing functions.

  • Specialized, Generalized, Efficient, Complex
  • Efficient, Complex, Generalized, Specialized
  • Complex, Generalized, Specialized, Efficient
  • Specialized, Efficient, Generalized, Complex
Currying allows the creation of more generalized versions of functions. By partially applying arguments, you can reuse and specialize functions for various scenarios.

How does recursion differ from iteration in JavaScript?

  • Recursion is more memory-efficient
  • Recursion uses a stack, while iteration uses a loop
  • Recursion is slower than iteration
  • Recursion is not supported in JavaScript
Recursion involves a function calling itself, creating a stack of function calls. In contrast, iteration uses loops for repetitive tasks. Understanding these differences is essential in choosing the right approach.

How do you import a specific function from a module in ES6?

  • import myFunction from 'module';
  • import { myFunction } from 'module';
  • import * as myFunction from 'module';
  • import myFunction as 'module';
To import a specific function from a module in ES6, you use the syntax import { myFunction } from 'module';. This allows you to bring in only the functions or variables you need rather than the entire module.

How are imports and exports handled differently in ES6 Modules compared to CommonJS?

  • Explicit import and export statements
  • Automatic global binding
  • Using require and module.exports
  • Implicit import and export statements
In ES6 Modules, imports and exports are explicit, and you use import and export statements to define dependencies. This is different from CommonJS, where dependencies are managed using require and module.exports.

Describe a scenario where using tagged template literals could be beneficial for sanitizing user input in a web application.

  • They enable the creation of custom sanitization functions to process user input.
  • They automatically escape special characters, preventing injection attacks.
  • They provide a mechanism to enforce strict input validation rules.
  • They allow for the easy integration of third-party sanitization libraries.
Tagged template literals allow developers to create custom sanitization functions, ensuring secure processing of user input and preventing potential injection attacks.