This in JavaScript
In JavaScript, the value of this is dynamic and typically determined by how a function is called. This means that what affects the value of this is not when it’s declared, but where it’s invoked.
There are 5 ways to determine the value of this:
- 
In a regular function call, thisrefers to the global object (theWindowobject in browsers in non-strict mode, orundefinedin strict mode).
- 
When a function is called as a method of an object, thisrefers to that object.
- 
When a function is called with the newkeyword, a new object is created before the function executes, andthisrefers to this newly created object.
- 
We can also use the apply,call, andbindmethods to explicitly specify which objectthisshould refer to.
- 
Arrow functions, introduced in ES6, don’t have their own thisvalue. Instead, they inheritthisfrom the nearest outer function. If that outer function is also an arrow function, it will continue looking up the scope chain. This process continues until it finds the defaultthisvalue in the global environment (e.g.,windowin browsers).
