Understanding JavaScript's 'this' Keyword

The JavaScript this keyword — small word, massive confusion. When I first started learning JavaScript, this was easily one of the most confusing concepts. Sometimes it pointed to window, sometimes an object, sometimes undefined. It felt like it had an identity crisis. So I finally sat down and wrote a blog to break it down clearly and practically — no textbook language, no unnecessary theory. In this post, I cover: What this actually is How it changes based on context Common mistakes developers make How to predict what this will refer to before running the code If you’re: Learning JavaScript Preparing for interviews Or revisiting fundamentals this might save you a lot of confusion. 👉 Read here: 🔗 https://lnkd.in/d2dRdH_M If you find it helpful, feel free to share — it might help someone else overcome their this identity crisis too 🙂 #JavaScript #WebDevelopment #Frontend #LearningInPublic #JSFundamentals #Developers

In short, 'this' is defined for every execution context which includes both global EC and function EC. I you try to access 'this' in the global scope, it will point to window. 1.For a normal function , it returns undefined (in strict mode) or window object (in sloppy mode) 2. Arrow functions don't get 'this' keyword so they take the value from outer scope 3. For event listener functions, this points to the dom element itself

To view or add a comment, sign in

Explore content categories