When an async function throws an error and it is not caught, it results in a rejected __________.

  • Promise
  • Error
  • Exception
  • Rejection
When an async function throws an unhandled error, it results in a rejected Promise. The rejection carries the error information, and if not caught using a catch block or try...catch, it can lead to unhandled promise rejections. Understanding this behavior is essential for effective error handling in asynchronous code. Properly handling promise rejections ensures that errors are appropriately addressed, preventing unintended consequences in the application.

When using fetch to make an HTTP request, how do you ensure that HTTP errors are caught?

  • response.ok
  • response.status
  • catch
  • handleError
To catch HTTP errors when using the fetch API, you can use the catch method. This method is chained to the Promise returned by fetch and allows you to handle network errors, as well as HTTP errors (e.g., 404 or 500). By providing a callback function to catch, you can manage and respond to errors that may occur during the request.

Using __________ at the beginning of an async function can help catch synchronous errors.

  • try/catch
  • await
  • throw
  • catch
Placing a try/catch block at the beginning of an async function allows you to catch and handle synchronous errors within the asynchronous context. This is important for comprehensive error handling in asynchronous code.

Currying in JavaScript can help in creating functions that are ________ to specific scenarios.

  • General
  • Flexible
  • Limited
  • Specialized
Currying in JavaScript can help in creating functions that are specialized to specific scenarios. Currying is a technique where a function with multiple arguments is transformed into a series of functions, each taking a single argument. This enables creating more specialized functions tailored to specific use cases.

When iterating over a Map object with a for...of loop, each iteration returns an array where the first element is the _______ and the second is the value.

  • key
  • index
  • property
  • length
In a Map object, the first element of the array returned during iteration represents the key, and the second element represents the corresponding value.

In functional composition, the output of function ______ becomes the input of function ______.

  • Output, Input, Result, Transformation
  • Transformation, Input, Output, Composition
  • Result, Transformation, Input, Output
  • Composition, Result, Output, Input
In functional composition, the output of one function serves as the input for the next one. This is a key concept in functional programming, where functions are chained together to perform a series of transformations on data.

Consider a library with multiple utility functions; how would you structure the exports to optimize for tree shaking?

  • export function util1() {} export function util2() {}
  • export { util1, util2 }
  • export default { util1, util2 }
  • export const util1 = () => {}; export const util2 = () => {};
To optimize for tree shaking, individually exporting functions (export function util1() {}) allows dead code elimination, ensuring only the used functions are included in the final bundle.

In object methods, using arrow functions can lead to issues when relying on the this keyword, as it does not bind its own this, but inherits it from the ________ scope.

  • Parent
  • Global
  • Lexical
  • Block
Arrow functions inherit the this value from their lexical scope, which means the scope in which they were defined. This can lead to unexpected behavior when used in object methods.

In Node.js, ES6 Modules have a different file extension (_________) compared to CommonJS modules (.js).

  • .mjs
  • .es6
  • .es
  • .node
Node.js uses the .mjs file extension for ES6 modules to differentiate them from CommonJS modules that typically use the .js extension. This helps Node.js to identify the module type and apply the appropriate module loading mechanism.

Can a static method in a parent class be overridden in a child class?

  • Yes
  • No
  • Depends on the method implementation
  • Only if explicitly declared as override
Yes, a static method in a parent class can be overridden in a child class. However, it's important to note that static methods are associated with the class itself rather than instances, and the child class can provide its own implementation of the static method, effectively overriding the one in the parent class.