Quiz Entry - updated: 2026.07.05
What are methods on JavaScript objects, and what does this refer to?
A method is just a function stored as a property of an object, and inside it this refers to the object that owns the method.
When a function is stored as one of an object's properties, it's called a method — it gives the object a behaviour, not just data. Inside a method, the special keyword this refers back to the object the method belongs to (its "owner"), so the method can read that object's other properties:
let person = {
firstName: 'Hans',
name: 'Meier',
fullName: function() {
return this.firstName + ' ' + this.name;
}
};
console.log(person.fullName()); // 'Hans Meier'
Here this.firstName and this.name reach into the same person object the method is attached to.
Two things to watch:
- Always call a method with parentheses:
person.fullName()runs it and returns'Hans Meier'. Without the(),person.fullNamegives you the function itself, not its result — a frequent mistake. - Modern JavaScript offers a shorthand that drops the
functionkeyword and the colon:
fullName() {
return this.firstName + ' ' + this.name;
}
Go deeper:
MDN:
this— whythisdepends on how a function is called, and how arrow functions inherit it from the enclosing scope.