Recall & Review
beginner
What is an instance method in JavaScript?
An instance method is a function defined inside a class that can be called on objects created from that class. It operates on the data (properties) of the specific object.Click to reveal answer
beginner
How do you define an instance method inside a JavaScript class?
Inside a class, you write a function without the 'function' keyword. For example:<br><pre>class Dog {
bark() {
console.log('Woof!');
}
}</pre>Click to reveal answer
beginner
Why do instance methods use 'this' keyword?
'this' refers to the specific object calling the method. It lets the method access or change that object's properties.
Click to reveal answer
beginner
Can instance methods access properties of the object? How?
Yes, instance methods access properties using 'this.propertyName'. For example, if an object has a 'name' property, the method can use 'this.name' to get or set it.
Click to reveal answer
beginner
What happens if you call an instance method without creating an object?
You get an error because instance methods belong to objects, not the class itself. You must create an object (instance) first to use them.Click to reveal answer
How do you call an instance method named 'greet' on an object 'person'?
✗ Incorrect
You call instance methods using the object name followed by a dot and the method name with parentheses.
Where are instance methods defined in JavaScript?
✗ Incorrect
Instance methods are defined inside the class body so all objects created from the class can use them.
What does 'this' refer to inside an instance method?
✗ Incorrect
'this' inside an instance method points to the specific object that called the method.
What happens if you try to call an instance method directly on the class without creating an object?
✗ Incorrect
Instance methods require an object to work on. Calling them on the class itself causes an error.
Which keyword is NOT used when defining an instance method inside a class?
✗ Incorrect
Inside a class, instance methods are defined without the 'function' keyword.
Explain what an instance method is and how it uses 'this' in JavaScript classes.
Think about how methods belong to objects created from classes.
You got /3 concepts.
Describe the steps to create a class with an instance method and call that method on an object.
Remember the order: class, method, object, call.
You got /4 concepts.