How does the "this" keyword behave inside a closure?

  • It refers to the global object.
  • It captures the value of "this" from the outer scope.
  • It is undefined.
  • It refers to the function's local scope.
Inside a JavaScript closure, the "this" keyword behaves by capturing the value of "this" from the outer scope where the closure is defined. This behavior is often used to maintain access to the enclosing context's data within the closure, avoiding issues with the global object or undefined values.
Add your answer
Loading...

Leave a comment

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