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

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 ES6, how is a method defined inside a class?

  • Using the function keyword
  • Using the method keyword
  • Using the def keyword
  • Using the => arrow syntax
In ES6, methods inside a class are defined using the => arrow syntax. This syntax provides a concise and cleaner way to declare methods within class definitions. It binds the method to the instance, allowing easy access to the class properties.