Single Choice Easy

QWhat does the this keyword refer to in the following code?
const user = {
name: 'John',
greet: () => {
console.log('Hello, ' + this.name + '!');
}
}

user.greet();

ID: #4914 Javascript Functions MCQ 327 views
Question Info
#4914Q ID
EasyDifficulty
Javascript Functions MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A the global object
  • B the function itself
  • C the object that the function is a property of
  • D the object that the function is called on
Correct Answer

Explanation

In this case, the greet function is an arrow function, which means that the this keyword is not dynamically bound to the object that the function is called on.
Instead, it refers to the value of this in the surrounding context, which in this case is the global object.

Share This Question

Challenge a friend or share with your study group.