Forums

Give help. Get help.

  • # January 23, 2018 at 1:08 pm

    //with using closure

    function wrapValue(n){
                var localVar = n;
                return function(){ return localVar;};       
            }
    var wrap1 = wrapValue(12);
            var wrap2 = wrapValue(24);
    
            console.log(wrap1());//12
    

    // I will try and do this

    function wrapValue(n){
                return n;
            }
    
            var variable1 = wrapValue(12);
    
            console.log(variable1);//12
    
            var variable2 = wrapValue(24);
    
            console.log(variable2);//24
    

    So, those two are basically same or not and when do i use closure?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag