Understanding how this is calculated in JS is one of the fundamental concepts in web development. Let us focus on some important points about it.

  • this is calculated at runtime
  • Unlike other languages, where methods defined in an object is always this referencing the object, in JavaScript this is free. Its value is evaluated at call time and doesn’t depend on where the caller method was declared rather on what is the object ‘before the dot’.

Now we will look at the cases where this can take different values for standard functions.

Standard Functions

Standard functions are the non-arrow functions. For e.g

this has troubled me for so long that I ended up making plethora of notes to get a hang of it, for once & for all. And finally, I have been able to conquer it to a large extent. I hope to help you do the same but faster.

In this article, I will be talking about how this behaves in an arrow function.

Note: we are considering non-strict mode for all intents & purposes of this article, so default global object will be windowobject.

Arrow Functions

These are compact expressions for writing smaller and compact functions but can be used like…

Monika Sahai

I am a professional front end web developer, aiming to become a full stack developer. I do digital drawing and love learning new frameworks.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store