Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

what is a closure in javascript

//Closures are the inner functions that are embedded in parent function
function getName(){
    // print name function is the closure since it is child function of getName
     function printName(){
         return 'Kevin'
     }
     // return our function definition
     return printName;
}

const checkNames = getName();
console.log(checkNames());
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #closure #javascript
ADD COMMENT
Topic
Name
4+4 =