In a nutshell, use const
for values that aren’t meant to change. In other words, constants.
Use let
for values that might change.
With ES6, we’ll rarely use var
anymore.
Using the old var
approach:
var name = 'Taro';
var title = 'Salesman';
var hourlySalary = 5000;
With ES6:
const name = 'Taro'; ← unlikely to change
let title = 'Salesman'; ← might change
let hourlySalary = 5000; ← might change
Using const
and let
makes your code more readable, especially for others.
A common practice is to initially write everything with const
and then switch to let
if you find you need to change the value later.