DEV Community

Abinaya V
Abinaya V

Posted on

Closure in JavaScript

A closure is a function that remembers and accesses variables from its outer scope even after the outer function has finished executing.

  • Retains access to outer function variables.

  • Preserves the lexical scope.

  • Allows data encapsulation and privacy.

  • Commonly used in callbacks and asynchronous code.

For example

input

output

Top comments (0)