Understanding of closure with function - Javascript Function

Javascript examples for Function:Closure

Description

Understanding of closure with function

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from w w  w  . jav a 2 s .  co m
function testClosure(){
 var x = 2;
    return function(y){
        console.log(eval(y));
    }
}
var closure = testClosure();
closure("x+2");
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials