75 lines
1.2 KiB
Plaintext
Raw Normal View History

include::../why.adoc[]
include::../how.adoc[]
2020-06-30 12:48:39 +02:00
=== Code examples
2020-06-30 12:48:39 +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
for (const i of input) {
if (i === target) {
2020-06-30 12:48:39 +02:00
return true;
}
}
return false;
}
----
==== Compliant solution
2020-06-30 12:48:39 +02:00
[source,javascript,diff-id=1,diff-type=compliant]
2020-06-30 12:48:39 +02:00
----
function seek(input) {
const target = 32;
for (const i of input) {
if (i === target) {
2020-06-30 12:48:39 +02:00
return true;
}
}
return false;
}
----
2020-06-30 12:48:39 +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;
}
----
==== 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]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Make "xxx" "const".
endif::env-github,rspecator-view[]