Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

closures in javascript

// A closure is a function having access to the parent scope, 
// even after the parent function has popped.

function greeting() {
    let message = 'Hi';

    function sayHi() {
        console.log(message);
    }

    return sayHi;
}
let hi = greeting();
hi(); // still can access the message variable
Source by www.javascripttutorial.net #
 
PREVIOUS NEXT
Tagged: #closures #javascript
ADD COMMENT
Topic
Name
7+6 =