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

52 lines
1.0 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.
== Noncompliant Code Example
[source,javascript]
----
function seek(input) {
let target = 32; // Noncompliant
for (let i of input) { // Noncompliant
if (i == target) {
return true;
}
}
return false;
}
function getUrl(query) {    
let url; // Noncompliant
url = "http://example.com";
return url;
}
----
== Compliant Solution
[source,javascript]
----
function seek(input) {
const target = 32;
for (const i of input) {
if (i == target) {
return true;
}
}
return false;
}
function getUrl(query) {  
const url = "http://example.com";
return url;
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]