ECMAScript 2015 introduced the let
and const
keywords for block-scope variable declaration. Using const
creates a read-only (constant) variable.
The distinction between the variable types created by var
and by let
is significant, and a switch to let
will help alleviate many of the variable scope issues which have caused confusion in the past.
Because these new keywords create more precise variable types, they are preferred in environments that support ECMAScript 2015. However, some
refactoring may be required by the switch from var
to let
, and you should be aware that they raise SyntaxError
s
in pre-ECMAScript 2015 environments.
This rule raises an issue when var
is used instead of const
or let
.
Noncompliant Code Example
var color = "blue";
var size = 4;
Compliant Solution
const color = "blue";
let size = 4;