const can be normally used when you don’t want your program
-
to assign anything to the variable
"use strict"; const a = 1; a = 2;will produce
TypeError: Assignment to constant variable.. -
to use the variable without explicitly initializing.
"use strict"; const a;will produce
SyntaxError: Unexpected token ;
Simply put, I would say,
-
use
constwhenever you want some variables not to be modified -
use
letif you want the exact opposite ofconst -
use
var, if you want to be compatible with ES5 implementations or if you want module/function level scope.
Use let only when you need block level scoping, otherwise using let or var would not make any difference.