I used to think JavaScript’s this was confusing for no reason. 😅
Then I realized the problem:
I was trying to memorize what this means instead of asking one simple question:
👉 “Who is calling this function?”
Once that clicked, things became much easier.
🔹 obj.method() → this usually refers to obj
🔹 Regular function → this depends on how the function is called
🔹 Arrow function → this comes from the surrounding scope
🔹 call(), apply(), bind() → you can explicitly control this
For example:
const user = {
name: "Shayon",
sayHi() {
console.log(
this.name);
}
};
user.sayHi(); // Shayon
Here, user is calling sayHi(), so this points to user.
💡 The biggest lesson?
Don't memorize dozens of this rules. First look at how the function is called.
I wrote more simple JavaScript explanations like this on my blog:
👉
blog.webdevlab.org
How did you learn JavaScript's this — by understanding it or memorizing the rules? 😄