2023-10-17 19:44:58 +02:00
|
|
|
|
include::../why.adoc[]
|
2023-05-03 11:06:20 +02:00
|
|
|
|
|
2023-10-17 19:44:58 +02:00
|
|
|
|
include::../how.adoc[]
|
2020-06-30 12:48:39 +02:00
|
|
|
|
|
2023-10-17 19:44:58 +02:00
|
|
|
|
=== Code examples
|
2020-06-30 12:48:39 +02:00
|
|
|
|
|
2023-10-17 19:44:58 +02:00
|
|
|
|
==== Noncompliant code example
|
|
|
|
|
|
|
|
|
|
[source,javascript,diff-id=1,diff-type=noncompliant]
|
2020-06-30 12:48:39 +02:00
|
|
|
|
----
|
|
|
|
|
function seek(input) {
|
|
|
|
|
let target = 32; // Noncompliant
|
2023-10-17 19:44:58 +02:00
|
|
|
|
for (const i of input) {
|
|
|
|
|
if (i === target) {
|
2020-06-30 12:48:39 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
----
|
|
|
|
|
|
2023-10-17 19:44:58 +02:00
|
|
|
|
==== Compliant solution
|
2020-06-30 12:48:39 +02:00
|
|
|
|
|
2023-10-17 19:44:58 +02:00
|
|
|
|
[source,javascript,diff-id=1,diff-type=compliant]
|
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) {
|
2023-10-17 19:44:58 +02:00
|
|
|
|
if (i === target) {
|
2020-06-30 12:48:39 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-10-17 19:44:58 +02:00
|
|
|
|
----
|
2020-06-30 12:48:39 +02:00
|
|
|
|
|
2023-10-17 19:44:58 +02:00
|
|
|
|
[source,javascript,diff-id=2,diff-type=noncompliant]
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
function getUrl(protocol, domain, path) {
|
|
|
|
|
let url; // Noncompliant
|
|
|
|
|
url = `${protocol}/${domain}/${path}`;
|
2020-06-30 12:48:39 +02:00
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
----
|
2023-10-17 19:44:58 +02:00
|
|
|
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
|
|
|
|
|
|
[source,javascript,diff-id=2,diff-type=compliant]
|
|
|
|
|
----
|
|
|
|
|
function getUrl(protocol, domain, path) {
|
|
|
|
|
const url = `${protocol}/${domain}/${path}`;
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
== Resources
|
|
|
|
|
|
|
|
|
|
=== Documentation
|
|
|
|
|
|
|
|
|
|
* MDN - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const[const]
|
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
== Implementation Specification
|
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
|
=== Message
|
|
|
|
|
|
|
|
|
|
Make "xxx" "const".
|
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|