What’s ‘this’?
In Javascript and programming in general, everything can seem to be a rigid science. There are only so many ways to get your program working with the correct specifications or within a certain timeframe. It either works…or there’s a big fat error message in your console, which is why the topic of ‘this’ is Javascript can be so confusing.
When I first ran into the concept ‘this,’ I was told its the assumed value within its context. I ran into two hard issues.
- I didn’t know we could assume anything in programming
- What does ‘this’ still mean?
The confusion lies in its ambiguity. ‘This’ can feel difficult to pin down because it changes based on context. The best explanation I have seen is viewing ‘this’ as like a pronoun.
In English, we use pronouns like ‘she’ or ‘her’ because its simpler, and the context is implied. ‘This’ is very much the same way, its context driven and simpler to use than rewriting what it references. So what does it reference?
Essentially, ‘this’ references the object left of the function in which it’s called or as Hack Reactor puts it ‘this’ is an identifier for values that refers to the likely-focal object.’ If you’re still as confused as I am, an example might help:
Now lets say Eric gets older which exacerbates his quarter life crisis, but happens anyway because life…
In the example above, we live in a world where ‘this’ doesn’t exist, meaning we can’t simplify our code to change per context. However if we include ‘this’ in our programming world:
Essentially, ‘this’ refers the object left of the dot. Many times, we will see ‘this’ used within functions that are used often for usable, repeatable code like increasing in age every year.
I hope this helped clarify things, and feedback and corrections are always encouraged.

