What happens if you try to use a for...of loop on an object that does not implement the iterable protocol?

  • It throws an error
  • It skips the object
  • It iterates over the properties
  • It prints 'undefined' for each iteration
If an object does not implement the iterable protocol, attempting to use a for...of loop on it will result in an error. Objects need to define the iterable protocol to be looped over using for...of.

In a situation where you have to iterate through a complex data structure (like a tree), how can generator functions simplify the process?

  • Enables pausing and resuming iteration
  • Provides deep cloning of data
  • Enhances recursive functions
  • Enables multithreading
Generator functions enable pausing and resuming iteration, making them ideal for traversing complex data structures like trees. The yield keyword allows you to pause the iteration at a specific point and then resume from where it left off, simplifying the handling of intricate data structures.

What is a potential pitfall when using multiple named exports in an ES6 module?

  • Naming conflicts and increased coupling
  • Improved encapsulation and modularity
  • Simplified import statements
  • Enhanced code maintainability
When using multiple named exports, naming conflicts may arise, leading to increased coupling between modules. It's important to carefully manage naming to avoid issues and maintain a modular code structure.

Which array method would you use to transform an array into a single value?

  • reduce
  • filter
  • forEach
  • map
The reduce method is used to transform an array into a single value by applying a function that accumulates the values of the array. It takes a callback function and an initial value, and iterates over the array, updating the accumulator with the result of the callback function. This is commonly used for summing up values or performing other aggregations.

Consider a scenario where you are managing a list of items in a shopping cart. Would you use let or const to declare the list, and why?

  • Use let
  • Use const
  • Either let or const, depending on the use case
  • It doesn't matter, both let and const work the same way
In this scenario, you would use const to declare the list because the shopping cart items should not be re-assigned. This enhances code safety and prevents accidental modifications.

What is the correct syntax to create an instance of a class in ES6?

  • let obj = new Class();
  • let obj = create(Class);
  • let obj = Object.create(Class);
  • let obj = Class.create();
The correct syntax to create an instance of a class in ES6 is to use the new keyword followed by the class name and parentheses, like this: let obj = new Class();. The new keyword is essential for creating instances and invoking the class constructor.

In a scenario where an application needs to make several API calls and only proceed after all have successfully completed, what Promise method would be most appropriate?

  • Promise.race
  • Promise.all
  • Promise.resolve
  • Promise.reject
When dealing with multiple asynchronous operations, Promise.all is used to wait for all promises to be resolved. It ensures that the application proceeds only when all the promises are successfully completed, making it suitable for scenarios where multiple API calls need to be made concurrently.

How does a for...of loop differ from a for...in loop in terms of iteration?

  • for...of is used for arrays and iterable objects
  • for...in is used for arrays and iterable objects
  • for...of iterates over property values
  • for...in iterates over property names
The for...of loop is designed specifically for iterating over values of iterable objects, such as arrays, while the for...in loop iterates over property names and is not limited to iterable objects.

When using fetch, convert the response to JSON inside a try block and handle errors in ________.

  • catch block
  • then block
  • finally block
  • parse block
When fetching data with the 'fetch' API, it's advisable to convert the response to JSON inside a try block to handle successful responses and catch block to handle errors.

In a web application that requires real-time data updates, how would the choice between Promises and callbacks affect performance and user experience?

  • Promises may offer better performance due to their asynchronous nature
  • Callbacks are preferable for real-time updates
  • There's no significant impact on performance or user experience
  • Promises introduce delays in real-time updates
In a web application requiring real-time data updates, choosing Promises may lead to better performance. Promises operate asynchronously, allowing non-blocking execution and potentially improving responsiveness. Callbacks, on the other hand, might result in callback hell and may not provide the same level of performance as Promises in handling real-time updates.

What is the significance of the "exports" field in package.json for an ES6 module?

  • Specifies the files to be exported
  • Defines the entry point of the module
  • Lists the dependencies for the module
  • Indicates the module's public API
The "exports" field in package.json is significant for an ES6 module as it defines the module's public API. It specifies which parts of the module can be accessed by other modules when imported. This helps in controlling the visibility of internal implementation details.

To handle errors within a generator function, the _________ method can be used alongside next().

  • throw
  • catch
  • try
  • finally
To handle errors in a generator function, the throw method can be used alongside the next() method. When an error is thrown, it is caught by the nearest catch block, allowing for graceful error handling within the generator.