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 :-


      function anyname(){

      var a = 10; //local variable

} </script>

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 a = 10;


      function anyname(){


}       function anyothername(){       document.write(a); } </script>

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