Javascript Variables

Most important characterstics of programming language is the type of data type.There are three types of data type in javascript.
  • Numbers-123,809 etc.
  • Strings-any alphabetical word or sentence.
  • Boolean-either true or false.

Javascript variables

Like many other programming languages javascript also consists of variables.Data can be placed in these variables and can be used whenever required. To use variables in javascript one must declare them.


var x;
var y;

Many variables can also declared in one line.

Using javascript many variables can be declared at once.Look at undergiven example.
var x,y,z;

Storing a value within a variable using javascript.

var x=250;
var y="ANKIT";

Javascript variable scope:

Javascript offers two scopes for programmers.Programmer may either declare a variable as a global variable or local variable.
  • Global Variables-A global variable in javascript has same value throughout the program.
  • Local Variable-A local variable is a variable whose value remains within only one particular function.
In javascript one must not use reserved variables like break or boolean etc.