A JavaScript global variable is declared outside the function or declared with window object. It can be accessed from any function.
Let’s see the simple example of global variable in JavaScript.
Declaring JavaScript global variable within function
To declare JavaScript global variables inside function, you need to use window object. For example:
Now it can be declared inside any function and can be accessed from any function. For example:
0 Comments