Do you want to be a good Web Developer?

Enter Your Email To Get Our Exclusive Tutorials
And Offer Right In Your Email

Javascript Variables

Javascript Variables

Variables are used to store values.Before you use a variable in a JavaScript program, you should declare it. Variables are declared with the var keyword.


var variableName;


var variableName = value;

Example of Variable

var m;
var i = 0, j = 0, k = 0;
var i = 13, j = 2, k = 432.42;

Variable Scope

It is the place where you can defined and use a variable. Variable Scope are of two types Global Variable, Local Variable.

  • Global Variable: global variables are those variables which is defined anywhere in your javascript code and you can use that variable wherever you want.

  • Local Variable: local variables are those variables which is defined within a javascript function and you can use that variable only in that function.You cannot use that variable outside from that function.

Example of Global Variable

var v=24;

Example of Local Variable

function demo()
var v=24;

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email