What is ‘this’ keyword in JavaScript?

Forums JavaScriptWhat is ‘this’ keyword in JavaScript?
Staff asked 2 years ago

Answers (1)

Add Answer
Jaydip Mali Marked As Accepted
Staff answered 2 years ago

What is this?

In JavaScript, the this keyword refers to an object.

Which object depends on how this is being invoked (used or called).

The this keyword refers to different objects depending on how it is used:

In an object method, this refers to the object.
Alone, this refers to the global object.
In a function, this refers to the global object.
In a function, in strict mode, this is undefined.
In an event, this refers to the element that received the event.
Methods like call(), apply(), and bind() can refer this to any object.

Note: this is not a variable. It is a keyword. You cannot change the value of this.

Subscribe

Select Categories