2021-01-27 13:42:22 +01:00
Marking a variable that is unchanged after initialization ``++const++`` is an indication to future maintainers that "no this isn't updated, and it's not supposed to be". ``++const++`` should be used in these situations in the interests of code clarity.
2020-06-30 12:48:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:48:39 +02:00
----
function seek(input) {
let target = 32; // Noncompliant
2021-04-26 17:29:13 +02:00
for (let i of input) { // Noncompliant
2020-06-30 12:48:39 +02:00
if (i == target) {
return true;
}
}
return false;
}
function getUrl(query) {
let url; // Noncompliant
url = "http://example.com";
return url;
}
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:48:39 +02:00
----
function seek(input) {
const target = 32;
2021-04-26 17:29:13 +02:00
for (const i of input) {
2020-06-30 12:48:39 +02:00
if (i == target) {
return true;
}
}
return false;
}
function getUrl(query) {
const url = "http://example.com";
return url;
}
----
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]