What is a closure in JavaScript?

  • A secure way to store passwords
  • A private function
  • A way to handle exceptions
  • A function that remembers its lexical scope
A closure in JavaScript is a function that "remembers" its lexical scope, even when it's executed outside that scope. This allows the function to maintain access to variables from its parent scope, creating a powerful mechanism for encapsulation and data privacy.
Add your answer
Loading...

Leave a comment

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