How do generator functions differ from traditional functions in terms of execution?

  • Generator functions have multiple entry points
  • Generator functions always return a value
  • Generator functions are synchronous
  • Generator functions have the ability to pause and resume execution
Generator functions differ from traditional functions by having the ability to pause and resume their execution using the yield keyword. This feature enables the creation of iterators and asynchronous programming patterns. Traditional functions, on the other hand, run to completion without the ability to pause.

Given a scenario where you need to flatten a deeply nested array, how would you implement this using recursion in ES6?

  • Use Array.prototype.concat with recursion to flatten the array.
  • Use a for...of loop to iterate through the array and flatten it.
  • Implement a reduce function with recursion to flatten the array.
  • Utilize the Array.prototype.flat method available in ES6.
In ES6, the reduce function can be leveraged along with recursion to flatten a deeply nested array effectively. The accumulator in reduce helps to accumulate the flattened result. This approach is versatile and applicable to various array structures. The other options either lack the necessary recursion or use methods not specifically designed for flattening deeply nested arrays.

How does the super keyword differ when used in static methods compared to non-static methods?

  • It behaves the same in both static and non-static methods
  • It is not allowed in static methods
  • It refers to the superclass in non-static and subclass in static methods
  • It is used to invoke the constructor of the superclass in both cases
In a static method, 'super' refers to the parent class, while in a non-static method, it points to the parent class. This is because static methods are called on the class itself, and non-static methods are called on instances of the class.

In ES6, how can you define a method inside an object literal?

  • Function shorthand notation
  • Method shorthand notation
  • Prototype method notation
  • Arrow function notation
In ES6 object literals, you can define a method using the method shorthand notation. This provides a concise way to declare functions as properties of an object.

Which method would you choose to execute a side effect for each array element without modifying the array?

  • forEach
  • map
  • filter
  • reduce
The forEach method is designed for executing a provided function once for each array element without modifying the array itself. It is commonly used when you need to perform side effects, such as logging or updating external variables, for each element.

Can mixins in ES6 access private data of the classes they are mixed into?

  • Yes, mixins have access to private data
  • No, mixins cannot access private data
  • It depends on the implementation of the mixin
  • Private data is accessible only during class instantiation
Mixins in ES6 do not have direct access to the private data of the classes they are mixed into. Private data remains encapsulated within the class, ensuring data integrity and security.

In a scenario with a mix of synchronous and asynchronous code, how does the call stack and event loop manage the execution?

  • The call stack executes synchronous code first.
  • The event loop processes asynchronous code first.
  • Both synchronous and asynchronous code are executed randomly.
  • The call stack and event loop have no interaction.
The call stack prioritizes synchronous code, while the event loop manages the execution of asynchronous code by pushing it to the callback queue and executing it when the call stack is empty.

How would you use a for...of loop to iterate over a string?

  • for (let char in myString)
  • for (let char of myString)
  • for (let i = 0; i < myString.length; i++)
  • for (let i = myString.length - 1; i >= 0; i--)
The correct syntax to iterate over a string using a for...of loop is for (let char of myString). This loop simplifies the process of iterating over the characters of a string without the need for an index.

In ES6, a module imported via a relative path starting with ______ indicates it is located in the same directory.

  • ./
  • ../
  • //
  • \
When using a relative path in ES6 for module imports, ./ is used to indicate that the module is in the same directory as the importing module.

A class expression in ES6 can be named or unnamed, with the name being accessible inside the class's ________.

  • Private Scope
  • Protected Scope
  • Public Scope
  • Local Scope
The name of a class in ES6 is accessible only within the class's block scope, making it part of the class's internal structure.