A function's In most cases, the value of A property of an execution context (global, function or eval) that, in non–strict
mode, is always a reference to an object and in strict mode can be any value. In the global execution context (outside of any function), Note: You can always easily get the global object using the global
Function context Inside a
function, the value of Since the following code is not in strict mode, and because the value of
In
strict mode, however, if the value of
Note: In the second example, To set the value of Class context The behavior of Within a class constructor,
Note: Static methods are not properties of Derived classes Unlike base class constructors, derived constructors have no initial Warning: Referring to Derived classes must not return before calling
Examplesthis in function contexts
this and object conversion
Note that in non–strict mode, with
The bind() method ECMAScript 5 introduced
Arrow functions In arrow functions,
Note: If
No matter what,
In the above, the function (call it anonymous function A) assigned to As an object method When a function is called as a method of an object, its In the following example, when
Note that this behavior is not at all affected by how or where the function was defined. In the previous example, we defined the function inline as the
This demonstrates that it matters only that the function was invoked from the Similarly, the
this on the object's prototype chain The same notion holds true for methods defined somewhere on the object's prototype chain. If the method is on an object's prototype chain,
In this example, the object assigned to the variable this with a getter or setter Again, the same notion holds true when a function is invoked from a getter or a setter. A function used as getter or setter has its
As a constructor When a function is used as a constructor (with the Note: While the default for a constructor
is to return the object referenced by
In the last example ( As a DOM event handler When a function is used as an event handler, its
In an inline event handler When the code is called from an inline on-event handler, its
The above alert shows
In this case, the inner function's this in classes Just like with regular functions, the value of
Note: Classes are always strict mode code. Calling methods with an undefined Specifications
Browser compatibilityBCD tables only load in the browser See alsoWhich is not a JavaScript keyword?JavaScript Keywords. Which one is not the keywords?Note: true , false , and null are not keywords, but they are literals and reserved words that cannot be used as identifiers.
Which is not reserved keyword in JavaScript?The NaN , Infinity , and undefined are not reserved keywords in JavaScript But you must avoid using them. They are properties of the global object and have special meanings.
Is name a keyword in JavaScript?Its not a javascript reserved word, its an html attribute. Any DOM element can have a name.
|