How do arrow functions treat this?
Options
- They bind
thisto the global object always - No own
this; it comes from the enclosing scope (Correct option) thisis always undefined inside every arrow- They treat
thisthe 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.