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.

How can you access both the index and value of an array element in a for...of loop?

  • for (let [index, value] of array.entries())
  • for (let {index, value} of array.entries())
  • for (let (index, value) of array.entries())
  • for (let index, value of array.entries())
In a for...of loop, you can use the entries() method on the array to access both the index and value. The returned value is an array where the first element is the index and the second element is the value. This destructuring assignment allows easy access to both index and value.

When you extend a class in ES6, what must you do before using this in the constructor?

  • Initialize the subclass properties
  • Call the super() method
  • Import the parent class
  • Define a new constructor
In ES6, when extending a class, you must call super() in the constructor of the subclass before using this. The super() call initializes the properties of the parent class.

In a subclass constructor, the super keyword must be called before accessing _______.

  • parent properties
  • child properties
  • subclass properties
  • constructor properties
In a subclass constructor, the super keyword must be called before accessing parent properties. This is because the super keyword refers to the parent class, and it needs to be invoked first to ensure that the parent's properties are properly initialized before accessing them in the subclass.

Imagine designing a class hierarchy for vehicles. How would you use constructors and the super keyword when creating a class for a specific type of vehicle, like a truck?

  • Utilize the constructor to initialize specific properties and use super to call the parent class constructor.
  • Ignore constructors and super, relying on default values for properties.
  • Use only the super keyword without constructors for simplicity.
  • Use constructors but avoid the super keyword for vehicle class creation.
In designing a class hierarchy, the constructor is crucial to initialize specific properties of the truck class. The super keyword ensures that the parent class constructor is called, setting up common attributes shared among all vehicles. This promotes code reusability and a clear inheritance structure.

In object destructuring, the rest operator can be used to gather the remaining properties into a new '__________'.

  • Object
  • Array
  • Variable
  • Function
In object destructuring, the rest operator (...) is used to collect the remaining properties of an object into a new array. This allows you to extract specific properties while capturing the rest in a convenient variable, often referred to as an array or an object.