Global variables in Javascript
by Ramya[ Edit ] 2010-06-17 15:52:26
Global variables in Javascript:
Normally we declare global variables outside all functions as,
var test = 5;
function result(){
var calc = parseInt(test)+5; //Something like that......
}
But if you want to define a variable as global inside a function then use the following steps:
* First, declare the variable as,
var Globalvar = value;
* Then use make it as global by using the keyword "window" as,
window.Globalvar = value;
for eg,
function test(){
var Globalvar = somevalue;
window.Globalvar = somevalue;
}
function test1(){
alert(window.Globalvar);
}