Posted by

What is Variable ?

Variable is just like a container which store the value into it .
ex- var x=6;
let y=x+z;

In above example x and y is a variable which store some value in it.
The variable is declare with var , let keyword.

In JavaScript we use var keyword for declaring the variable. var is use to specify the datatype of the value,It can hold any type of value such as numeric , string etc;

ex- var name =”Subham ,Karan, Musahid “; // in this variable we store string value inside name variable.
var Mob_no =1000100; //in this we store numeric value inside this variable.

Types of Variable.

There are two types of variables :-

1- Global variable

global variable is declared outside the function or declared with window object. It can be accessed from any function.

EX:- global variable

var value=50;    //global variable  
function a()
function b()

2- Local variable

A JavaScript local variable is declared inside block or function. It is accessible within the function or block only.

EX:- Local variable

function abc()
var x=10;    //local variable  

Datatype In JavaScript.

JavaScript provides two type of datatype for storing variable..

  1. Primitive Datatype
    1. String :- For storing sequence of the character.
    2. Number :- To represent numeric value in the variable.
    3. Boolean :- Store one value either true or false.
    4. Undefined :- Represent undefine variable.
    5. Null :- Store null value only.
  2. Non-Primitive Datatype
    1. Object :- Represents instance through which we can access members.
    2. Array :- Store collection of similar datatype.