×

Html & Html5

The World's best Software Development Study Portal

JS global variable


As we earlier discussed that the Javascript variable is used to simply name the storage location. And if these variable can be declared outside from the function or loop than it can be accessible from any function and also known to be the global variable.It is not having any limited scope.

Let's understand this by the following example:-

var marks = 50;

<script>

      function ramesh(){

      document.write(marks);

}

      function your(){

      alert(marks);

}

document.write(marks);

</script>

Output of this program:-

50

50

So this is the global variable which is not having the limited scope. And can be accessed by anywhere. And everytime you refreshing this page a popup box will be coming in front of you and that is just because of the alert command.






JS training insitute | Best IT Training classes in Gurgaon | Web Designing Training Institute