Single Choice Easy

QWhat does the this keyword refer to in the following code?
function greet() {
console.log('Hello, ' + this.name + '!');
}

ID: #4913 Javascript Functions MCQ 267 views
Question Info
#4913Q 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 a property of an object, and the this keyword refers to that object.

Share This Question

Challenge a friend or share with your study group.