Javascript Closures

Many people are looking for JavaScript learning experience simple and covering info without confusion. I thought to introduce a series of ‘SimpleCards’ to explain JavaScript concepts in effective and efficient way. To avoid confusion on JS Closure concept I made a simple card for it.
Definition (Mozilla Docs): Closures are functions whose inner functions refer to independent (free) variables (variables that are used locally, but defined in an enclosing scope). In other words, the functions defined in the closure ‘remember’ the environment in which they were created
Simply: A closure is a special kind of object that combines two things: a function + environment in which that function were created.
Pros:

  • Bind a variable to an execution context
  • Emulating private methods with closures

Cons: Unnecessarily create closures will affect script performance both in terms of

  • Processing speed and
  • Memory consumption
    JavaScript Closures
    JavaScript Closures

Leave a Reply

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