whatstheoutput_

#79: Calling regular vs arrow with .call

Topic: this · Difficulty: ★★

const target = { value: 42 };
function regular() { return this; }
const arrow = () => this;
console.log(regular.call(target) === target);
console.log(arrow.call(target) === target);

Output

true
false

Why

regular is an ordinary function, so its this is decided at call time: .call(target) explicitly sets this to target, and the function returns exactly that object, so the comparison is true. Arrow functions have no this slot of their own to set — they permanently use whatever this was in scope where they were written, and .call/.apply/.bind cannot override that (the this argument is simply ignored for arrows). arrow's this is the lexical (surrounding) this, which is not target, so arrow.call(target) still returns the outer this and the comparison is false.

More this puzzles

Play today's puzzle →