Javascript Function Closure Nested Function Scope

Description

Javascript Function Closure Nested Function Scope


// Demonstrating the scope properties of closures
function addFive(theVal) {
    function addNumber(howmany) {
        return theVal+howmany;
    }/*from  w ww  . j  a  v a2  s . co  m*/
    return addNumber(5);
}
console.log( addFive(15) );    // 20



PreviousNext

Related