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.


Syntax


var variableName;


Or


var variableName = value;

Example of Variable

var m;
var v = "HELLO JAVASCRIPT";
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;
}
PreviousNext

Subscribe Our Newsletter And Get Tutorials
And Offers Via Email

Subscribe Our Newsletter And Get Tutorials And Offers Via Email