this keyword in javascript with example
Example 1: use of this keyword in js
The JavaScript this keyword refers to the object it belongs to.
It has different values depending on where it is used: In a method,
this refers to the owner object. Alone, this refers to the global
object.
Example 2: js this in object
var wF = {
w : 560,
h : function() { return (312 - 42) / (560 / this.w) + 42; }
};
alert(wF.h())
Example 3: how to use this in js
console.log(this === window);
a = 37;
console.log(window.a);
this.b = "MDN";
console.log(window.b)
console.log(b)