this Binding Rules in JavaScript
From the JavaScript cheat sheet · The "this" Keyword · verified Jul 2026
this Binding Rules
How this is determined in different contexts
javascript
// Global context
console.log(this); // window (browser) or global (Node)
// Object method
const obj = {
name: 'Object',
greet() {
console.log(this.name); // 'Object'
}
};
// Function context
function regular() {
console.log(this); // window or undefined (strict)
}
// Arrow functions
const arrow = () => {
console.log(this); // inherits from parent
};💡 Arrow functions don't have own this, they inherit from parent
⚡ In strict mode, this is undefined in regular functions
📌 Method borrowing loses this context
🔥 Event handlers set this to the element that triggered event