Javascript examples for Data Type:Variable Scope
Define scoped variable with nested function and Get scoped variable
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from ww w . j av a 2 s. co m*/ var counter = 0; var foo; function myFunc() { this.foo = function() { counter = 1000; } } foo = new myFunc(); foo.foo(); document.getElementById('result').textContent = counter; } </script> </head> <body> <div id="result"></div> </body> </html>