Let's revisit the three keywords we can use to declare variables:
|Variable can be re-assigned?||yes||yes||no|
|Variable is limited to the block where it was defined?||no||yes||yes|
const have advantages over
var has no advantage over either of them.
let to define variables that will change. For example, if we plan to do math on a variable, we should use
let so we can change its value.
const create variables that can only be accessed within the block where they were defined.
The general rule is to use
const whenever you can, but if you need to change the variable use
Since we have
const, we don't have a good reason to use the
var keyword anymore.