Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Explain closure in JavaScript.

user-image
Question ajoutée par Rizwan Shah , Project Manager , COMSATS IIT
Date de publication: 2014/09/30
Hassan Naqvi
par Hassan Naqvi , Manager Web Portal , Innovative Solutions

A closer is a function inside a function that access a variable outside its scope. It is important to know a closure may or may not return a value.

 

Example:

=======

function count() {

    var i =0;  // name is a local variable created by init

    function countNum() {    // countNum() is a function inside a function, A Closure 

        i +=1;  // 'i' is a variable declared in the parent function outside countNum()   

    }

    countNum();    

}

count();

More Questions Like This