
The Magic of `this`, `call()`, `apply()`, and `bind()` in JavaScript
One of the most confusing concepts for beginners in JavaScript is the keyword this . Sometimes this refers to an object, sometimes it refers to something else, and sometimes it doesn’t behave the way we expect. Once you understand how this works and how methods like call() , apply() , and bind() control it, many JavaScript concepts start making much more sense. In this article, we will explore these concepts in a simple and practical way. Topics Covered In this blog we will learn: What this means in JavaScript this inside normal functions this inside objects What call() does What apply() does What bind() does Differences between call , apply , and bind What Does this Mean in JavaScript? A simple way to understand this is: this refers to the object that is calling the function. In other words, this depends on who is executing the function . this Inside Normal Functions In a regular function, this does not automatically refer to a specific object. Example: function greet () { console . l
Continue reading on Dev.to JavaScript
Opens in a new tab


