How to prove that arrow function does not have "this"

This article was published on Jan 12, 2021, and takes approximately a minute to read.

Arrow function has not its own scope. Instead it resolves it lexically which means that "it has access to whatever exists in the place where it's been created".

Keep this in mind, it's not like "the this of arrow function is lexical". Actually it's "arrow function DOES NOT have this".

To prove that you can try to call an arrow function with call(), apply(), or bind() and it'll throw an error saying that.

Copied
var obj = {
  num: 100,
};

var addFun = function (a, b, c) {
  return this.num + a + b + c;
};
console.log(addFun.call(obj, 1,2,3)); // 106

var addArrow = (a, b, c) => this.num + a + b + c;
console.log(addArrow.call(obj, 1,2,3)); //> NaN (because "this"" is undefined

Resources