2017  Kodetalk | Feedback | Privacy Policy | Terms | About

How does the “this” keyword work?

How does this work and when should it be used? or when it shouldn"t be used

Here a small story on this which give you the clarity regarding how "this" keyword is working in Javascript.

We use this similar to the way we use pronouns in natural languages like English and French. We write, “John is running fast because he is trying to catch the train.” Note the use of the pronoun “he.” We could have written this: “John is running fast because John is trying to catch the train.” We don’t reuse “John” in this manner, for if we do, our family, friends, and colleagues would abandon us. Yes, they would. Well, maybe not your family, but those of us with fair-weather friends and colleagues. In a similar graceful manner, in JavaScript, we use the this keyword as a shortcut, a reference; it refers to an object; that is, the subject in context, or the .

For better understanding on this please visit the blog http://javascriptissexy.com/understand-javascripts-this-with-clarity-and-master-it/

Answer is