What are closures?
We are all familiar with closures. We have used them many times, and they are one of the most familiar ways to apply a function to a piece of code. You might have also used closures to deal with side effects. However, they are not considered to be the best way to deal with side effects; instead, functional programming is the best way to go.
Those of you who don’t know what closures are, they are simply functions that have access to variables from the declaration of the function and from the surrounding code. Basically, a closure is a way to make private variables visible to a function. When we declare a function that takes in a variable or function, we define a closure that has access to the variable or functions outside variables.