View Full Version : Global variable
dealwi8me
05-12-2003, 06:26 PM
I have just started using JavaScript and i just wanted to ask how can i add a global variable or a static variable???
Thanks in advance! :)
beetle
05-12-2003, 07:12 PM
<head>
<script type="text/javascript">
var myGlobalVar = someValue;
</script>
</head>
Basically, any variable declared outside of a function is in the global scope. To declare a global from inside a function you must set it as a property of the window object (all global-scope variables are already window properties)
function someFunction()
{
window.myGlobalVar = someValue;
}
dealwi8me
05-12-2003, 07:22 PM
Thank you for your help :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.