Repaso
Español
Frontend & WebIntermediateFE-05

How do arrow functions treat this?

Options

  1. They bind this to the global object always
  2. No own this; it comes from the enclosing scope (Correct option)
  3. this is always undefined inside every arrow
  4. They treat this the same as regular functions

Answer

They have no own this; they capture it lexically from the enclosing scope

Why

In a normal function, this depends on HOW the function is called (e.g. obj.method() → obj), which often breaks when you pass it as a callback.

Arrow functions don't have their own this; they use the this of the code around them. That makes them perfect for callbacks inside methods.

Don't use arrows for object methods that need this to be the object.

Remember

Arrow functions borrow this from where they are written.

Key terms

Practice this question in Repaso