closure example

PHOTO EMBED

Tue May 21 2024 06:30:13 GMT+0000 (Coordinated Universal Time)

Saved by @ishwarpatel22

function outerFunction() {
    let outerVariable = "I am outside!";

    function innerFunction() {
        console.log(outerVariable);
    }

    return innerFunction;
}

const closureExample = outerFunction();
closureExample(); // Output: "I am outside!"
content_copyCOPY

lexical scope woks here