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.


Which keyword is used to refer to the parent class within a derived class method?

  1. parent

  2. super

  3. base

  4. this

The correct answer is: super

The keyword used to refer to the parent class within a derived class method is "super." This keyword is essential in object-oriented programming, especially in languages like JavaScript that support prototypal inheritance. When you use "super" within a derived class, it allows you to call functions and access properties of the parent class. In JavaScript, for example, when you define a subclass, you can use "super()" in the constructor to call the constructor of the parent class. This ensures that any initialization conducted by the parent class is executed before the derived class can add its enhancements. Additionally, using "super" enables access to overridden methods from the parent class, allowing developers to extend and customize behavior effectively. The other terms — "parent," "base," and "this" — do not serve the same function. "Parent" is not a recognized keyword in JavaScript for referring to a parent class; "base" is commonly used in other programming languages but does not exist in JavaScript for this purpose. Lastly, "this" refers to the current instance of the class and does not indicate the parent class, making "super" the correct and appropriate choice in this context.