How does the yield keyword function in the context of iterators and iterables?

  • Pauses the execution and returns a value to the iterator
  • Ends the iterator immediately
  • Skips the next iteration
  • Continues the execution without interruption
In the context of iterators and iterables, the yield keyword is used to pause the execution of a generator function, returning a value to the iterator. When the generator is later called again, it resumes execution from where it was paused.

What method is used to specify the code to execute after a Promise is fulfilled?

  • then()
  • catch()
  • resolve()
  • reject()
The then() method is used to specify the code that should be executed after a Promise is fulfilled. It allows you to handle the successful resolution of a Promise and work with the result.

If you have a configuration object that should not be altered during the execution of a program, how would you declare it using ES6 syntax?

  • Declare using let
  • Declare using const
  • Declare using var
  • Declare using readonly (ES6 feature)
You would declare the configuration object using const, as it ensures the object remains constant throughout the program execution, preventing unintended changes.

Consider a situation where you have an array of user objects. How would you implement an iterator to selectively process only certain users?

  • Use the filter method to create a new array with the selected users
  • Implement a custom iterator with a conditional statement inside the next method
  • Use the map method to selectively process users
  • Utilize the reduce method to iterate and selectively process users
Implementing a custom iterator is a powerful approach in this scenario. By creating a custom iterator, you have fine-grained control over the iteration process, allowing you to selectively process specific users based on the conditions defined in the iterator's next method.

Using yield* within a generator function delegates to another _________ or iterable object.

  • Generator
  • Function
  • Object
  • Array
In JavaScript, the yield* statement is used within a generator function to delegate to another generator or iterable object. The yield* expression iterates over the provided iterable, effectively delegating to each element's value.

A rejected promise will skip all subsequent .then() methods until a _________ method is found.

  • finally()
  • catch()
  • reject()
  • resolve()
The correct method is catch(). When a Promise is rejected, it will skip all subsequent then() methods and look for a catch() method in the chain to handle the rejection. The catch() method is used to specify what to do in case of a rejected Promise.

When higher-order functions are used for asynchronous programming, they often involve __________ to handle future results.

  • Callbacks
  • Closures
  • Promises
  • Observables
Promises are a type of higher-order function used for handling asynchronous operations in JavaScript. They provide a clean and structured way to work with asynchronous code by representing a value that might be available now, in the future, or never.

How can you handle potential undefined values when destructuring an object?

  • Ignore the value
  • Provide default values
  • Throw an error
  • Use try-catch block
When destructuring an object, you can provide default values to handle potential undefined values. If the property is not present in the object, the default value will be used. This helps prevent errors due to missing properties.

Can a for...of loop be used to iterate over a generator function's yielded values?

  • Yes, a for...of loop can iterate over the yielded values of a generator function.
  • No, for...of loops are not compatible with generator functions.
  • Yes, but it requires additional syntax.
  • No, generator functions can only be iterated using for...in loops.
Yes, a for...of loop can be used to iterate over a generator function's yielded values. The for...of loop automatically iterates over the values yielded by the generator, making it a convenient and readable way to consume generator values.

In ES6, class properties are often initialized inside the ________ method.

  • initialize
  • constructor
  • create
  • new
Class properties in ES6 are commonly initialized inside the constructor method. This allows you to set initial values for properties when an object is created.