JavaScript : Variables

JavaScript : Variables

Something which changes over time.

Variables are names identifiers for values. We declare variables in javascript using var and let keywords. See both declarations below.

//var declaration
var name;      

//let declaration
let age;

Differences between both declarations,

varletconst
declares a function scope variable if defined inside of a function, otherwise a global/module scope.declares a block scope variable.declares a block scope variable
optionally initializes to a valueoptionally initializes to a valueNeed to initialize while declaration.
declarations are hoisted to the top of the function scope.Not hoistedNot hoisted