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

Can call() change this in an arrow function?

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

JavaScript
const getX = () => this.x;
console.log(getX.call({ x: 1 }));
Show answer and explanation

The answer is undefined.

Arrow functions don’t have their own this, so call can’t set one. The first argument is ignored and this comes from the surrounding scope, which has no x.

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. Can you change this on a bound function with call()?
  4. Why does an arrow function in setTimeout keep this?
  5. What is the difference between call and apply in JavaScript?

Related topics