JavaScript Code

JavaScript Variables


Variables

variables are used to store values, they act as containers

x = 5;

value 5 is stored in x

var x = 5;

x is declared as variable, and value of 5 is assigned to it. x can be redeclared in the same block

const x = 5;

x is declared a constant, and the value once assigned, cannot be changed

let x = 5;

x is assigned a value of 5, and the x cannot be redeclared in the same block-scope

a = 4;
b = 2;
c = a + b;

variables can be used in expressions like a + b. Values of a, and b are substituted in place of them