change a JavaScript global variable - Javascript Data Type

Javascript examples for Data Type:Variable Scope

Description

change a JavaScript global variable

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() {/*w w w  .  j av a 2 s  . c om*/
x = "1.0";
y = "2.0";
$ = x;
withLib = (function(callback, $) {
  callback($)
})
withLib(function($){
    console.log($, $ == "2.0" ? "outer success" : 'outer fail')
    my = function() {
        console.log($, $=="2.0" ? "inner success" : "inner fail")
    }
}, y);
my();
    });

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

Related Tutorials