ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Explain closure in JavaScript.

user-image
تم إضافة السؤال من قبل Rizwan Shah , Project Manager , COMSATS IIT
تاريخ النشر: 2014/09/30
Hassan Naqvi
من قبل 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();

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟