this in JavaScript refers to the object that is currently calling a function.Its value is decided when the function runs, based on how it is called.
Common Meanings of this
- Global scope → window (in browser)
- Regular function
-Non-strict mode → window
-Strict mode → undefined
- Object method → the object itself
- Arrow function → inherits this from surrounding scope
- Event handler → the HTML element
- Class method → the class instance
- call / apply / bind → this is explicitly set
1.Global Context
In Browser
✔ Refers to the window object
In Strict Mode
✔ undefined
2.Inside a Function
Normal Function (Non-Strict)
✔ this → window
Strict Mode
✔ this → undefined
