Back to articles
Understanding this keyword in javaScript

Understanding this keyword in javaScript

via Dev.to WebdevAbhishek sahni

If you work in JavaScript, you have probably seen the this keyword many times. Many developers have a basic understanding of it, but there is still a lot of confusion around it because its behaviour changes depending on the current context. What is this keyword : Let’s understand the this keyword with an example. Think of this as an actor. An actor changes their role in every movie depending on the context of the movie. Similarly, the this keyword also behaves like an actor because it changes its behaviour according to the current context in JavaScript. Definition of this word : this keyword is reference to the object of currently executing functions. its value is not static. It is determined at runtime based on how a function is called. Now let's see behaviour of this keyword in various different context . this in Global context : In browser : this in the global context refers to the window object. In Node.js, when you use this in the global context (at the top of a file, outside all

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles