How does the "this" keyword behave in arrow functions compared to regular functions?

  • It refers to the global object.
  • It retains the value of "this" from its enclosing lexical context.
  • It becomes undefined.
  • It refers to the parent function's "this".
In arrow functions, the value of "this" is determined by its enclosing lexical context (the function that contains it). This behavior is different from regular functions, where "this" is dynamically scoped and can change based on how the function is called. This makes arrow functions particularly useful for maintaining the expected value of "this" in functions defined within methods or callbacks.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *