|
|
Global variables in Javascript - Javascript
|
Views : 282
|
|
Tagged in : Javascript
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
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);
}
|
|
By Ramya, On - 2010-06-17 |
|
|
|