this keyword in JavaScript !!!
What is this
in JS:
Value of this keyword represents globalObject.
Global Object vary in different-different runtime environments.
In case of Browser Global Object is Window. In case Node.js Global Object is global.
strict and non-strict mode:
this shows different behaviour in strict and non -strict mode.
In non-strict mode, if we try to access this keyword inside function, it will return undefined.
If we use strict-mode, we will get GlobalObject.
this with function:
How we call function also changes nature of this keyword.
If we simply call function with strict-mode it returns undefined.
If we call function with Global Object it returns us Window, which is global object in case of bowsers.
this with Objects:
If we use this keyword inside object, its reference to the object.
We can access properties and methods of object using this keyword.
[[ posting it unfinished, cant complete this in one stretch... 🥲 ]]
Top comments (0)