Can you use destructuring assignment to assign default values to variables?

  • Yes
  • No
  • Only for primitive data types
  • Only for arrays
Yes, destructuring assignment in ES6 allows you to assign default values to variables. If the assigned value is undefined, the variable takes the default value specified. This feature enhances flexibility in handling variable assignments.

What is the main difference between default exports and named exports in ES6 modules?

  • Default exports are used for exporting a single value or function, while named exports are used for exporting multiple values or functions from a module.
  • Default exports use the export default syntax, while named exports use the export { myFunction }; syntax.
  • Default exports are mandatory, while named exports are optional.
  • Default exports can be renamed during import using the as keyword, while named exports cannot be renamed.
The main difference is that default exports are for a single value or function, and named exports are for multiple values or functions. Default exports use export default while named exports use export { myFunction };.

What happens when you try to import a non-existent named export from a module?

  • It will result in an error at runtime.
  • It will import the default export instead.
  • It will create an empty object for the named export.
  • It will import all exports from the module.
If you try to import a non-existent named export, it will result in an error at runtime. It's important to ensure that the named exports you are trying to import actually exist in the module.

How does ES6 handle importing a module that is located in a node_modules folder?

  • Looks for the module in the current directory first, then checks the node_modules folder
  • Directly looks in the node_modules folder
  • Prioritizes searching in the node_modules folder before checking the current directory
  • Searches both the current directory and the node_modules folder simultaneously
In ES6, when importing a module, the resolution algorithm prioritizes searching the node_modules folder before checking the current directory. This allows for better organization of dependencies and avoids naming conflicts with local modules. It simplifies the module import process and enhances code maintainability by following a standardized approach to handle third-party libraries.

ES6 arrow functions can make recursive functions more concise and _________.

  • Readable
  • Performant
  • Maintainable
  • Shorter
ES6 arrow functions, with their concise syntax, can make recursive functions shorter and more readable by eliminating the need for the 'function' keyword and providing implicit returns.

How does the yield* keyword differ from yield in a generator function?

  • Both are equivalent
  • yield* is used for delegating to another generator or iterable
  • yield is used for async operations
  • yield* is used for synchronous operations
The yield* keyword in a generator function is used for delegating to another generator or iterable. It allows you to compose generators and is often used for iterating over iterable objects within the generator function. On the other hand, yield is used to pause the generator and yield a value to the caller.

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.