What is the this keyword in JavaScript?

this refers to the object that is calling the function.

  • In an object method, this is the object before the dot.
  • In a normal function, this is undefined (strict mode) or the global object.
  • In an arrow function, this is taken from the surrounding code.
  • With new, this is the new object.
const user = {
  name: "Robin",
  show() { console.log(this.name); }
};
user.show();

Output:

Tutorials Class - Output Window

Robin

See The this keyword.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.