JavaScript · Middle · Question 5 of 75
What does this code print?
const obj = {
name: "Ann",
hi: () => this.name,
};
console.log(obj.hi());- ✓Correct answer:
undefined: the arrow takesthisfrom the outer scope, not the object - 2
"Ann": an arrow method is always bound to its object - 3
SyntaxError: arrows can't be declared in object literals
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.