Variables are containers that hold data. They help us store, reuse, and update information in JavaScript — from simple values like numbers to complex data like arrays and objects. Think of a variable as a box with a name on it. You can put something inside it (a value), and later check or change what's inside.
In JavaScript, you create these boxes using keywords: var , let , or const.
varletconst
These 2 words will be used later
- hoisted Find reference for hoisted in [hositing.md]. Before reading temporal deadzone understand this concept.
- temporal dead zone(tdz) Find reference for tdz in [tdz.md].
- part ES5js
- function scoped
- can be redeclared and reassigned
- hoisted to top with
undefinedvalue.
- part of latest ES6js features
- block scoped
- can be reassigned but can't be redeclared
- hoisted but stays in
temporal dead zone(tdz)
- part of latest ES6js features
- block scoped
- can't be reassigned but cant be redeclared
- hoisted but stays in
temporal dead zone(tdz)
Use Const as much as possible.
Use Let only when you plan to redeclare the value again.
Avoid Var its part of old ES script and creates bug.