Marco Borgeaud 95ce8c6119
Diff blocks: fix some incorrect use for javascript (#2802)
Improvement identified in #2790.

Add a prefix to the diff-id when it is used multiple times in different
"how to fix it in XYZ" sections to avoid ambiguity and pedantically
follow the spec:

> A single and unique diff-id should be used only once for each type of
code example as shown in the description of a rule.

Obvious typos around `diff-type` were fixed.
2023-08-15 09:43:48 +02:00

47 lines
1.4 KiB
Plaintext

== Why is this an issue?
include::../description.adoc[]
Additionally, these literals will throw SyntaxError in strict mode. 0-prefixed octal literals have been deprecated since ECMAScript 5 and should not be used in modern JavaScript code.
[source,javascript,diff-id=1,diff-type=noncompliant]
----
const myNumber = 010; // Noncompliant: Deprecated format
----
Use decimal syntax when possible as it is more readable.
[source,javascript,diff-id=1,diff-type=compliant]
----
const myNumber = 8;
----
If octal notation is required, use the standard syntax: a leading zero followed by a lowercase or uppercase Latin letter "O" (`0o` or `0O`).
[source,javascript,diff-id=1,diff-type=compliant]
----
const myNumber = 0o10;
----
== Resources
=== Documentation
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#octal_numbers[MDN - Octal numbers]
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal[MDN - SyntaxError: "0"-prefixed octal literals are deprecated]
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode[MDN - Strict mode]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]