Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

Can you change this on a bound function with call()?

Do you know what will be the output of this code?

JavaScript
function greet() {
  return this.name;
}

const bound = greet.bind({ name: "Ana" });
console.log(bound.call({ name: "Bob" }));
Show answer and explanation

The answer is "Ana".

bind returns a new function with this permanently set. call and apply can’t override it. Only new can, and that’s rarely what you want.

Take the full quiz Next question →

More this questions

  1. Why does this become undefined when you extract a method?
  2. Why does an arrow function method return undefined for this?
  3. Why does an arrow function in setTimeout keep this?
  4. What is the difference between call and apply in JavaScript?
  5. What happens when a constructor returns an object?

Related topics