Hi friends, As we know that if we declared a variable outside the function of javascript, then it is said to be global variable. But this is not a correct way to declare global variable.
Correct way to declare global variable in JavaScript is-
when a global variable is set, it's added to the window object & use the syntax like this:
var window.GlobalVar = "Hello";
For Example
var window.GlobalVar = "Hello";
function Hello()
{
alert(window.GlobalVar);
//OR
alert(GlobalVar);
}
By doing in this way, JavaScript will be more robust and reliable.
0 Comment(s)