In a class hierarchy, if a method is overridden, how can you call the method from the parent class?

  • Using this.method()
  • super.method()
  • parent.method()
  • class.method()
The 'super' keyword is used to call the overridden method from the parent class. It ensures that the overridden method in the subclass is bypassed, and the method from the parent class is invoked.

How do mixins in ES6 help in achieving multiple inheritance?

  • Through Object Assignment
  • Using Class Hierarchy
  • Prototypal Inheritance
  • Closures
Mixins in ES6 are achieved by applying the properties and methods of one object to another using object assignment. This allows a single object to inherit functionalities from multiple sources, providing a form of multiple inheritance. Mixins enhance code reuse and flexibility by allowing the composition of behavior from different objects.

When overriding a method in a subclass, use super.methodName() to call the original method from the _______ class.

  • child
  • parent
  • subclass
  • overridden
When overriding a method in a subclass, use super.methodName() to call the original method from the parent class. This allows the subclass to extend or modify the behavior of the parent method while still utilizing its functionality.

A const declaration ensures that the variable's __________ cannot be reassigned.

  • type
  • value
  • identity
  • scope
The correct option is 'value'. When a variable is declared with 'const' in JavaScript, its value cannot be reassigned. However, it's important to note that the const declaration does not make the variable itself immutable; it only ensures that the binding of the variable to a value remains constant.

To prevent modifications to an object’s prototype, the _________ method can be used to seal the prototype.

  • Freeze
  • Seal
  • PreventExtensions
  • Protect
The seal method in JavaScript can be used to prevent any further addition or deletion of properties on an object, including its prototype. This ensures that the prototype remains fixed and cannot be modified.

How do you access a static property within a class method?

  • Using this.propertyName
  • Using self.propertyName
  • Using the class name followed by a dot and the property name
  • Using super.propertyName
To access a static property within a class method, you use the class name followed by a dot and the property name. This is because static properties are associated with the class itself, not with instances, so you reference them through the class name.

To iterate over an array's elements using a for...of loop, write for (const element _______ array).

  • in
  • of
  • from
  • within
In JavaScript, the correct syntax for iterating over an array using a for...of loop is for (const element of array). The of keyword is used to loop over the values in an iterable object like an array.

Can async functions be used as constructors for new objects?

  • Yes
  • No
  • Only in specific JavaScript engines
  • Only with the use of decorators
No, async functions cannot be used as constructors for new objects. Async functions always return a Promise, and using them with the new keyword will result in a TypeError. Constructors should return objects, not Promises.

To handle errors in an async function, you should use a try...catch __________.

  • Block
  • Clause
  • Mechanism
  • Statement
To catch errors in an async function, you should use a try...catch statement. This helps in graceful error handling and prevents unhandled promise rejections.

In a Promise, if an error is not caught, it leads to a(n) ________.

  • Rejection
  • Resolution
  • Exception
  • Completion
In a Promise, when an error occurs and is not caught, the Promise is rejected. This can lead to unhandled promise rejections, causing issues in the application. Understanding how to handle promise rejections is crucial in asynchronous programming with Promises.