Can the super keyword be used in a class that does not extend another class?

  • Yes
  • No
  • Only in static methods
  • Only in arrow functions
No, the super keyword is used to call corresponding methods of the superclass in a subclass. If a class doesn't extend another class, there is no superclass, and using super is not valid.

In a recursive function, how can default parameters be used to track state across recursive calls?

  • Utilize default parameter values to maintain state
  • Use default parameters only for base cases
  • Default parameters are not suitable for recursive functions
  • Recursive functions cannot use default parameters
In a recursive function, default parameters can be leveraged to maintain state across different recursive calls. This allows you to pass and update values without explicitly passing them in each recursive call. For example, consider a factorial function where the default parameter keeps track of the current product.

How do Symbols contribute to better property encapsulation in objects?

  • Symbols allow for private properties
  • Symbols allow for dynamic property names
  • Symbols enforce strict encapsulation
  • Symbols are interchangeable with property names
Symbols in JavaScript can be used as unique keys for object properties. This allows for the creation of private properties and better encapsulation, as Symbols are not enumerable in for...in loops and do not clash with other property names.

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.

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.