| Viewed 189 times

How to declare global variable in javascript


How to declare global variable in javascript

1 Answer
Mohammad Qandeel
Answered
5

In javascript global variable can be declared by

  • declared outside the function¬†
  • declared with the window object

and it can be accessed from anywhere from the code

Example "1"

window.value='Qandeel';// by window object  

function a(){  
alert(value);  
} 
a();

Example "2"

var value=50;//global scope

function a(){  
alert(value);  
} 
a();