-
var:
- The traditional way of declaring variables.
- Functional scoped
- Can be redeclared
-
let:
- Introduced in ES6 (2015),
let allows you to declare block-scoped variables.
- Block scoped
- Cannot be redeclared
-
const:
- Also introduced in ES6,
const declares variables that cannot be reassigned after their initial assignment.
- Block scoped
- Cannot be redeclared & has to be initialized while declaring
var x; // Declaration only
let y = 10; // Declaration and initialization
const z = "Hello"; // Declaration and initialization (must be initialized)
Resources