Nested Function returning - Javascript Function

Javascript examples for Function:Function Return

Description

Nested Function returning

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width"> 
   </head> 
   <body> 
      <script>
function counter() {//from   w ww .  ja va 2  s.c o m
 var x = 0;
  function internal() {
    x++;
   return x;
 }
internal.toString=function(){return internal().toString();};
return internal;
};
console.log(counter());
var count=counter();
console.log(count);
console.log(count);
console.log(count);

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

Related Tutorials