2022-02-04 16:28:24 +00:00

47 lines
1.2 KiB
Plaintext

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
[source,javascript]
----
var color = "blue";
var size = 4;
----
== Compliant Solution
[source,javascript]
----
const color = "blue";
let size = 4;
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]