JavaScript · Middle · Question 5 of 75

What does this code print?

const obj = {
  name: "Ann",
  hi: () => this.name,
};
console.log(obj.hi());

Explanation

An object literal doesn't create its own scope for this. The arrow takes this from the module or global scope. That's why object methods are declared with the regular hi() {} syntax.

Further reading

Problem with a question

JavaScript · Middle · question 5

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz