🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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" }));
  1. A.Hi Asha undefined
  2. B.Hi Ravi string
  3. C.Hi Asha string
  4. 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 →