Posts

Deep Dive: Mastering the JavaScript this Keyword

Hey there! If you’ve ever tried logging this in JavaScript and got undefined or something totally unexpected, you’re not alone. The this keyword is one of the trickiest parts of JS—but once you get it, it makes your code way cleaner and easier to debug. In this guide, we’ll break down this in simple terms and show how it works in: Global context Strict vs non-strict mode Normal functions Object methods Arrow functions Classes and constructors Explicit binding with call , apply , and bind What is this in JavaScript? Simply put: this is the object that’s currently running the function. The main rule to remember: it depends on how the function is called, not where it’s written. this in the Global Context When you use this in the global scope: console.log(this); In a browser → it points to window In Node.js → it points to global Pretty str...

Popular posts from this blog

Deep Dive: Mastering the JavaScript this Keyword