← Quiz: Scope, Closures, Hoisting and this: all 15 questions
Quiz: Scope, Closures, Hoisting and this · Question 13 of 15
What does this print? (code)
What does this print?
const user = {
name: "Asha",
hi() { return "Hi " + this.name; },
};
const f = user.hi;
console.log(user.hi(), typeof f.call({ name: "Ravi" }));
- A.Hi Asha undefined
- B.Hi Ravi string
- C.Hi Asha string
- D.It throws an error
Answer & explanation
Correct answer: Hi Asha string
Called as user.hi(), this is user; call sets this to the object passed, and the result is a string.
Can you get the rest right without peeking?
Take the timed Quiz: Scope, Closures, Hoisting and this quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →