In JavaScript, the thing called this, is the object that "owns" the JavaScript code. The value of this, when used in a function, is the object that "owns" the function. The value of this, when used in an object, is the object itself.
The (this) keyword is one of the most widely used and yet confusing keyword in JavaScript. (this) keyword points to a particular object. Now, which is that object is depends on how a function which includes 'this' keyword is being called.
JavaScript is the programming or scripting language and it creates dynamically control multimedia, animated images. ‘This’ keyword is powerful global object & it is one of the most misunderstood parts of JavaScript and this keyword is using for execution the context. For example:-
function f1() {
return this;
}
// In a browser:
f1() === window; // true
// In Node:
f1() === global; //
This keyword in an object constructor does not have a value. It is only a substitute for the new object.The value of this will become the new object when the constructor is used to create an object.
In Javascript, property of an object can be a method or a simple value. When an Object's method is invoked then “this” refers to the object which contains the method being invoked.
A function's this keyword behaves a little differently in JavaScript compared to other languages. It also has some differences between strict mode and non-strict mode.
In most cases, the value of this is determined by how a function is called. It can't be set by assignment during execution, and it may be different each time the function is called.