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.

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.

Default parameters can be combined with object destructuring to construct complex default values.

  • Object Literals
  • Object Destructuring
  • Object Prototypes
  • Object Methods
ES6 introduced object destructuring, allowing you to extract values from objects easily. When combined with default parameters, it becomes a powerful feature for defining functions with complex default values. The correct option, "Object Destructuring," signifies this technique.

If you are refactoring a set of classes representing different types of user accounts in a system, how would constructors and super assist in initializing properties common to all account types?

  • Utilize constructors in each class without the super keyword.
  • Rely on global variables to initialize common properties.
  • Use the super keyword to invoke the parent class constructor for shared properties.
  • Avoid constructors altogether and rely on setter methods.
Constructors and the super keyword are essential in refactoring user account classes. Constructors help initialize class-specific properties, while super facilitates the invocation of the parent class constructor, ensuring that common properties are appropriately initialized across all account types.

What is the impact of ES6 Modules on asynchronous loading and module bundling tools compared to CommonJS?

  • Increased bundle size due to module encapsulation
  • Improved parallel loading of modules
  • Slower loading of dependencies
  • Limited compatibility with bundling tools
ES6 Modules support asynchronous loading and enable parallel loading of modules, improving performance. Additionally, they work seamlessly with modern module bundlers, leading to more efficient bundling and reduced bundle size.

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.

In which scenarios are dynamic imports particularly useful?

  • Small Applications
  • Large Applications with Code Splitting Needs
  • Static Applications
  • Mobile Applications Only
Dynamic imports are particularly useful in large applications where code splitting is necessary. This allows loading only the required modules on-demand, reducing the initial load time and improving overall application performance. Small and static applications may not benefit as much from dynamic imports.

When a function returns a new object each time it is called, even with the same inputs, is it considered a pure function?

  • Yes
  • No
  • Depends on the type of object
  • Only if the object is immutable
A pure function should consistently return the same result for the same inputs, and creating new objects introduces unpredictability, making it impure.