You would have used this frequently in javascript. Here is one example of this

var name = "techdomain"
function getName(){
    return this.name
}
getName();
> techdomain"

Here this refers to name ie "techdomain"

this and window object

In browser land, the window object is the root object. Every frame has a new window object. The window object refers to the window that loads the DOM (Document Object Model), while document object refers to the DOM.

So the this keyword will refer to window object in browser

this inside function scope

Normally this refers to window object in browser. But in "strict" mode, this will be undefined inside function.

"use strict"
var name = "nodejs";
function getthis(){
    return this;
}
getthis();
> undefined

this and arrow function

In arrow function, the scope is inherited. So this.name will be "nodejs"

"use strict"
var name = "nodejs";
var getname = () => {
    return this.name;
}
getname();
> nodejs

this and bind function

You can use bind to bind a context to a function. As shown below, we are binding different context to the function. So this.name will be "bind-nodejs" and not "nodejs"

"use strict"
var name = "nodejs";
var getname = () => {
    return this.name;
}
getname.bind({name: 'bind-nodejs'})();
> bind-nodejs

You can read more on why do we need to bind functions in react jsx.

this in nodejs

In nodejs, there is no window object available. In nodejs, this refers to empty object.

console.log(this);

Now run this file using nodejs

node index.js
> {}

If you assign something to this, it will be assigned to empty object. For example

console.log(this);
this.name = "nodejs";
console.log(this);

When you run this file using nodejs,

node index.js
> {}
> { name: "nodejs" }