Html & Html5

The World's best Software Development Study Portal

JS variable

A Javascript variable is used to simply a name of storage location.There are mainly two types of variables and they are as follows:-

  • Local variables
  • Global Variable

Local Variables

Inside a block or function if any variable is declared . It is accessible within the function or block only.

Let's understand this by the following example :-


      var a = 10;

     var b = 20;

      var c = a+b;

      document.write(c);//local variable



Basically it means that it is having the limited scope.

Global variable

If any variable is accessible from any function than the function declared with in the window object is known to be the global variable.It is not having any limited scope.


var data= 20; //Global variable

      function x(){



      function y(){



x();//Calling Javascript function




So this is the lobal variable which is not having the limited scope.

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