Closures are functions that have access to variables in the scope of another function.

The above explanation comes from the advanced JavaScript tutorial

The learning closure concept is analyzed in several steps

  • Creating an Application Scenario
  • Use closures to solve problems

Application Scenarios:

In collaborative projects, in order to avoid some exceptions, we would consider creating private variables inside the function, exposing only common methods for external calls, and not being able to modify the values inside the function externally to reduce external interference with the variables.

Create private variables using closures:

In addition to private variables, the most used is the anti – shake function.

Closures are well explained on the web, and the best way to learn about closures is to look for solutions in application scenarios.