Day 5 : JavaScript Closures

In this blog, we are going to understand the closure concept in JavaScript. Closures in JavaScript : The closures are the important and some what complex concept in JavaScript. Before we go to closures we have to known about life of variables and scopes in JavaScript. Life of variables : 1) Global variables - Global variables have long lives. They are created at the beginning of the program and they live until the page or program is discarded. 2) Local variables - Local variables have short lives. They are created when the function is invoked and deleted when the function is finished. Scope : As we all know we can’t get data from an outside scope. JavaScript doesn’t have the public, private, protected access modifiers. For security or accessibility in JavaScript we use closures. Every closure has three scopes: Local scope, Ou...