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
JavaScript Functions
JavaScript Arrow Functions
Constructor Functions in JavaScript
JavaScript this Keyword
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What are arrow functions in JavaScript?
What is the this keyword in JavaScript?
What is the difference between call, apply and bind?
What is the difference between debounce and throttle?
What is the difference between function declaration and function expression?
What is a closure in JavaScript?