I used to think JavaScript’s this was confusing for no reason. 😅 Then I realized the problem: I ...I used to think JavaScript’s this was confusing for no reason. 😅 Then I realized the problem: I ...
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
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? 😄
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started