Q: A class's instances that are present inside of a method's body behave in a certain way according to
-
A
from
-
B
to
-
C
this
-
D
object
C
Answer:
C
Explanation:
In object-oriented programming, the this keyword is used to refer to the current object. It is commonly used inside the body of a class's methods to refer to the object on which the method is being called.
For example, consider the following class:
class Person {
constructor(name) {
this.name = name;
}
sayHello() {
console.log(`Hello, my name is ${this.name}`);
}
}
Here, the Person class has a constructor function that takes a name parameter and assigns it to the name property of the object being created.
The class also has a method called sayHello that prints a greeting to the console using the name property of the object.
Related Topic:
Share Above MCQ