Jeroen Wiert Pluimers @wiert@mastodon.social on X: “@_ObomheseR Since JavaScript is in the group of curly based programming languages influenced by the B programming language, integer constants starting with zero are tried first in octal base. 017 octal is 15 decimal 018 octal is not possible, so becomes 18.”
Posted by jpluimers on 2025/08/20
With the constant influx of JavaScript programmers, it keeps worth repeating that you should always run JavaScript in strict mode via "use strict"; (like in the past Visual Basic 6 developers should use option strict and option explicit) to forget risky JavaScript syntax like implicit ocal constants (which were removed from the documentation in the 2009 ECMAScript 5 specification for JavaScript), and every codeline should have a test code covering it, especially for comparisons involving non-strict behaviour like the use of leading zeros.
As of the succeeding 2015 standard (ECMAScript 6), octal numbers in JavaScript start with 0o or 0O followed by a series of octal digits.
Oh, and the history of octal in computing of course has to do with 6-bit systems and also lead to 6-six bit character codes including BCD character encoding..
My tweet back earlier this year: [WaybackSave/Archive] Jeroen Wiert Pluimers @wiert@mastodon.social on X: “@_ObomheseR Since JavaScript is in the group of curly based programming languages influenced by the B programming language, integer constants starting with zero are tried first in octal base. 017 octal is 15 decimal 018 octal is not possible, so becomes 18.”
Inhteritence:
The tweet above is slightly wrong in two areas:
- I got the term curly bracket programming language wrong
- The B programming language does actually use curly brackets, but that feature was actually introduced by BCPL from which B derived from and in turn influenced the C programming language
As a side note, List of C-family programming languages – Wikipedia does include BCPL, but not B. Luckily List of programming languages by type: Curly bracket languages – Wikipedia contains both.
References:
- [Wayback/Archive] The B Tutorial Guide having sections on constancs with
6.1 Decimal Integers:
Standard decimal integers are given with no decimal point and no leading zeroes. Below are some examples.3 7 254000 678
6.2 Octal Integers:
Standard octal integers are given with at least one leading zero. Decimal points are not permitted. Octal integers can only use the digits from zero to seven. Below are some examples.010 0777777 004567 00000
- B (programming language) – Wikipedia
- Unix – Wikipedia
- JavaScript/Strict mode – Wikibooks, open books for an open world
- ECMAScript version history – Wikipedia
- [Wayback/Archive] The Moth – Option Explicit and Option Strict in VB
- [Wayback/Archive] Strict mode – JavaScript | MDN
- [Wayback/Archive] ECMA-262_5th_edition_december_2009.pdf [Wayback PDF View/PDF View] (there is no HTML equivalent of this document)
Past editions of ECMAScript have included additional syntax and semantics for specifying octal literals and
octal escape sequences. These have been removed from this edition of ECMAScript.…
More is in the below 5.1 HTML as that has slight fixes to the 5.0 version.
- [Wayback/Archive] ECMA-262_5.1_edition_june_2011.pdf [Wayback PDF View/PDF View] and [Wayback/Archive] ECMAScript Language Specification – ECMA-262 Edition 5.1
A conforming implementation, when processing strict mode code (see 10.1.1), must not extend the syntax of NumericLiteral to include OctalIntegerLiteral as described in B.1.1.
…
A conforming implementation, when processing strict mode code (see 10.1.1), may not extend the syntax of EscapeSequence to include OctalEscapeSequence as described in B.1.2.
…
10.1.1 Strict Mode Code
An ECMAScript Program syntactic unit may be processed using either unrestricted or strict mode syntax and semantics. When processed using strict mode the three types of ECMAScript code are referred to as strict global code, strict eval code, and strict function code.
…
Annex B (informative)Compatibility
B.1 Additional Syntax
Past editions of ECMAScript have included additional syntax and semantics for specifying octal literals and octal escape sequences. These have been removed from this edition of ECMAScript. This non-normative annex presents uniform syntax and semantics for octal literals and octal escape sequences for compatibility with some older ECMAScript programs.
B.1.1 Numeric Literals
The syntax and semantics of 7.8.3 can be extended as follows except that this extension is not allowed for strict mode code:
Syntax
NumericLiteral ::DecimalLiteralHexIntegerLiteralOctalIntegerLiteralOctalIntegerLiteral ::0OctalDigitOctalIntegerLiteral OctalDigitOctalDigit :: one of01234567Semantics
- The MV of NumericLiteral :: OctalIntegerLiteral is the MV of OctalIntegerLiteral.
- The MV of OctalDigit ::
0is 0. - The MV of OctalDigit ::
1is 1. - The MV of OctalDigit ::
2is 2. - The MV of OctalDigit ::
3is 3. - The MV of OctalDigit ::
4is 4. - The MV of OctalDigit ::
5is 5. - The MV of OctalDigit ::
6is 6. - The MV of OctalDigit ::
7is 7. - The MV of OctalIntegerLiteral ::
0OctalDigit is the MV of OctalDigit. - The MV of OctalIntegerLiteral :: OctalIntegerLiteral OctalDigit is (the MV of OctalIntegerLiteral times 8) plus the MV of OctalDigit.
B.1.2 String Literals
The syntax and semantics of 7.8.4 can be extended as follows except that this extension is not allowed for strict mode code:
Syntax
EscapeSequence ::CharacterEscapeSequenceOctalEscapeSequenceHexEscapeSequenceUnicodeEscapeSequenceOctalEscapeSequence ::OctalDigit [lookahead ∉ DecimalDigit]ZeroToThree OctalDigit [lookahead ∉ DecimalDigit]FourToSeven OctalDigitZeroToThree OctalDigit OctalDigitZeroToThree :: one of0123FourToSeven :: one of4567Semantics
- The CV of EscapeSequence :: OctalEscapeSequence is the CV of the OctalEscapeSequence.
- The CV of OctalEscapeSequence :: OctalDigit [lookahead ∉ DecimalDigit] is the character whose code unit value is the MV of the OctalDigit.
- The CV of OctalEscapeSequence :: ZeroToThree OctalDigit [lookahead ∉ DecimalDigit] is the character whose code unit value is (8 times the MV of the ZeroToThree) plus the MV of the OctalDigit.
- The CV of OctalEscapeSequence :: FourToSeven OctalDigit is the character whose code unit value is (8 times the MV of the FourToSeven) plus the MV of the OctalDigit.
- The CV of OctalEscapeSequence :: ZeroToThree OctalDigit OctalDigit is the character whose code unit value is (64 (that is, 82) times the MV of the ZeroToThree) plus (8 times the MV of the first OctalDigit) plus the MV of the second OctalDigit.
- The MV of ZeroToThree ::
0is 0. - The MV of ZeroToThree ::
1is 1. - The MV of ZeroToThree ::
2is 2. - The MV of ZeroToThree ::
3is 3. - The MV of FourToSeven ::
4is 4. - The MV of FourToSeven ::
5is 5. - The MV of FourToSeven ::
6is 6. - The MV of FourToSeven ::
7is 7.
…
15.1.2.2: The specification of the function
parseIntno longer allows implementations to treat Strings beginning with a0character as octal values.…
- [Wayback/Archive] ECMA-262_6th_edition_june_2015.pdf [Wayback PDF View/PDF View] and [Wayback/Archive] ECMAScript 2015 Language Specification – ECMA-262 6th Edition has the
0oand0Ooctal notation, similar to the0x 0Xhexadecimal one:
…
OctalIntegerLiteral ::0oOctalDigits0OOctalDigitsOctalDigits ::OctalDigitOctalDigits OctalDigitOctalDigit ::
one of01234567HexIntegerLiteral ::0xHexDigits0XHexDigitsHexDigits ::HexDigitHexDigits HexDigitHexDigit ::
one of0123456789abcdefABCDEF…
This continues in the most recent version at the time of writing:
- [Wayback/Archive] ECMA-262 – Ecma International reintroduces the LegacyOctalIntegerLiteral notation and documents the NonOctalDecimalIntegerLiteral and LegacyOctalLikeDecimalIntegerLiteral notations that can also start with a
0
-
…NumericLiteralSeparator ::
_…
OctalIntegerLiteral ::0oOctalDigits0OOctalDigitsOctalDigits ::OctalDigitOctalDigits OctalDigitOctalDigits NumericLiteralSeparator OctalDigitLegacyOctalIntegerLiteral ::0OctalDigitLegacyOctalIntegerLiteral OctalDigitNonOctalDecimalIntegerLiteral ::0NonOctalDigitLegacyOctalLikeDecimalIntegerLiteral NonOctalDigitNonOctalDecimalIntegerLiteral DecimalDigitLegacyOctalLikeDecimalIntegerLiteral ::0OctalDigitLegacyOctalLikeDecimalIntegerLiteral OctalDigitOctalDigit :: one of01234567NonOctalDigit :: one of89HexIntegerLiteral ::0xHexDigits0XHexDigitsHexDigits ::HexDigitHexDigits HexDigitHexDigits NumericLiteralSeparator HexDigitHexDigit :: one of0123456789abcdefABCDEF…
This part was really hard to copy from the specifications because most of their formatting is being done with non-HTML elements starting with
<emu-. One would expect their markup system to emit HTML, but it emits an HTML superset which is then rendered by JavaScript. Hopefully for them this doesn’t kill accessibility, but it does make copying their content a lot harder. References:- [Wayback/Archive] GitHub – domenic/emu-algify: Use Ecmarkup’s elements in your HTML
- [Wayback/Archive] GitHub – bterlson/ecmarkdown: A shorthand language for writing ECMAScript-style algorithms, inspired by Markdown
- [Wayback/Archive] GitHub – tc39/ecmarkdown: A shorthand language for writing ECMAScript-style algorithms, inspired by Markdown
- [Wayback/Archive] GitHub – tc39/ecmarkup: An HTML superset/Markdown subset source format for ECMAScript and related specifications
- [Wayback/Archive] Ecmarkup
My tweet above was in response to [Wayback/Archive] ORM 𝕏 on X: “Who can explain?? “:
[Wayback/Archive] Gjg5l7KWcAAE5C8.jpg:orig (748×716)
index.js
console.log(018 == '018');
console.log(019 == '019');Default node index.js
true
false
--jeroen







Leave a comment