Prepare for the Salesforce JavaScript Developer Exam. Utilize comprehensive quizzes, flashcards, and multiple choice questions with hints and explanations. Boost your exam readiness!

Practice this question and more.


In a class that extends another class, what method is used to call the parent class's constructor?

  1. call()

  2. super()

  3. init()

  4. constructor()

The correct answer is: super()

In JavaScript, when working with classes that extend other classes, the correct way to call the parent class's constructor is by using the `super()` method. This allows the child class to access and initialize properties of the parent class before executing its own constructor. When you define a class that extends another class, you need to call `super()` within your constructor before you can use `this`. The `super()` function will invoke the constructor of the parent class, ensuring that any inherited properties and methods are properly set up. For example, within the child class, if you don't call `super()`, you would encounter a reference error when trying to access `this`, as it hasn't been defined yet. This mechanism allows for a clear inheritance structure and ensures that the child class can appropriately extend the functionality of the parent class. The options that do not relate to this specific task like `call()`, `init()`, and `constructor()` do not serve this purpose in the context of class inheritance. `call()` is used for function invocation, `init()` is not a standard method in JavaScript classes, and while `constructor()` is indeed the name of the constructor method, it does not specifically call the parent constructor—the `super()`