js strict can check more error and make your cede quick run . the code as: <script type="text/javascript"> 'use strict' function doing(){ employee=1; } doing(); alert(employee) </script> the console would export error that employee has not defined , you can declaraction 'use strict' to join strict mode. ofcourse you can delaraction variable by window Object as: <script type="text/javascript"> function doing(){ window.demo=1; } doing() alert(window.demo) </script> the demo will be gloabe variable it is will be ok