41 lines
806 B
Plaintext
Raw Normal View History

2020-12-23 14:59:06 +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
----
function seek(input) {
let target = 32; // Noncompliant
for (let i of input) {
if (i == target) {
return true;
}
}
return false;
}
function getUrl(query) {    
let url; // Noncompliant
url = "http://example.com";
return url;
}
----
== Compliant Solution
----
function seek(input) {
const target = 32;
for (let i of input) {
if (i == target) {
return true;
}
}
return false;
}
function getUrl(query) {  
const url = "http://example.com";
return url;
}
----