Posted By

khaled on 09/09/10


Tagged


Versions (?)

Local & Global Variable in Javascript


 / Published in: JavaScript
 

  1. <script type="text/javascript">
  2.  
  3. var MyVariable = 'global';
  4.  
  5. function x()
  6. {
  7. var MyVariable = 'local';
  8. alert('x: ' + MyVariable);
  9. }
  10.  
  11. function y()
  12. {
  13. alert('y: ' + MyVariable);
  14. }
  15.  
  16.  
  17. x();
  18. y();
  19. </script>

Report this snippet  

You need to login to post a comment.