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.

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 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.

The __________ is a JavaScript runtime feature that constantly checks if the call stack is empty to run queued callbacks.

  • Event Loop
  • Callback Queue
  • Microtask Queue
  • Execution Context
The correct option is Event Loop. The Event Loop is a crucial part of JavaScript's concurrency model. It continuously checks the call stack, and when it's empty, it picks up and executes tasks from the callback queue. Understanding the Event Loop is essential for writing efficient and non-blocking code.

How does the behavior of 'this' in arrow functions affect their usage as methods in an object?

  • It does not affect 'this' binding
  • It binds 'this' to the object instance
  • It binds 'this' to the global object
  • It depends on the calling context
Arrow functions do not bind their own 'this' and instead inherit it from the surrounding scope. When used as methods in an object, this can lead to unintended behavior as 'this' will not refer to the object itself, potentially causing bugs.

How do dynamic imports affect the performance of a web application?

  • Increase Performance
  • Decrease Performance
  • No Impact
  • Depends on Implementation
Dynamic Imports can potentially decrease the initial load time of a web application by loading modules asynchronously. This can lead to improved performance, especially in scenarios where not all modules are required immediately. However, the actual impact depends on various factors, such as network conditions and how dynamic imports are implemented.

What happens when an iterator's next() method returns an object with done: true?

  • It means the iteration is complete, and further calls to next() will throw an error
  • It indicates an error in the iteration process
  • It signals an infinite loop in the iteration
  • It signifies that there are more elements to be iterated
When the next() method returns an object with done set to true, it indicates that the iteration has reached its end, and there are no more elements to be processed. Subsequent calls to next() will continue to return objects with done: true, providing a clear signal that the iteration is complete.

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.

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.

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.