The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

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:

  1. I got the term curly bracket programming language wrong
  2. 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 ::
    DecimalLiteral
    HexIntegerLiteral
    OctalIntegerLiteral
    OctalIntegerLiteral ::
    0 OctalDigit
    OctalIntegerLiteral OctalDigit
    OctalDigit :: one of
    0 1 2 3 4 5 6 7

    Semantics

    • The MV of NumericLiteral :: OctalIntegerLiteral is the MV of OctalIntegerLiteral.
    • The MV of OctalDigit :: 0 is 0.
    • The MV of OctalDigit :: 1 is 1.
    • The MV of OctalDigit :: 2 is 2.
    • The MV of OctalDigit :: 3 is 3.
    • The MV of OctalDigit :: 4 is 4.
    • The MV of OctalDigit :: 5 is 5.
    • The MV of OctalDigit :: 6 is 6.
    • The MV of OctalDigit :: 7 is 7.
    • The MV of OctalIntegerLiteral :: 0 OctalDigit 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 ::
    CharacterEscapeSequence
    OctalEscapeSequence
    HexEscapeSequence
    UnicodeEscapeSequence
    OctalEscapeSequence ::
    OctalDigit [lookahead ∉ DecimalDigit]
    ZeroToThree OctalDigit [lookahead ∉ DecimalDigit]
    FourToSeven OctalDigit
    ZeroToThree OctalDigit OctalDigit
    ZeroToThree :: one of
    0 1 2 3
    FourToSeven :: one of
    4 5 6 7

    Semantics

    • 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 :: 0 is 0.
    • The MV of ZeroToThree :: 1 is 1.
    • The MV of ZeroToThree :: 2 is 2.
    • The MV of ZeroToThree :: 3 is 3.
    • The MV of FourToSeven :: 4 is 4.
    • The MV of FourToSeven :: 5 is 5.
    • The MV of FourToSeven :: 6 is 6.
    • The MV of FourToSeven :: 7 is 7.

    15.1.2.2: The specification of the function parseInt no longer allows implementations to treat Strings beginning with a 0 character 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 0o and 0O octal notation, similar to the 0x 0X hexadecimal one:

    OctalIntegerLiteral ::
    0o OctalDigits
    0O OctalDigits
    OctalDigits ::
    OctalDigit
    OctalDigits OctalDigit
    OctalDigit ::

    one of 0 1 2 3 4 5 6 7
    HexIntegerLiteral ::
    0x HexDigits
    0X HexDigits
    HexDigits ::
    HexDigit
    HexDigits HexDigit
    HexDigit ::

    one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F

    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

My tweet above was in response to [Wayback/Archive] ORM 𝕏 on X: “Who can explain?? “:

[Wayback/Archive] Gjg5l7KWcAAE5C8.jpg:orig (748×716)

[Wayback/Archive] Tweet JSON

index.js

console.log(018 == '018');
console.log(019 == '019');

Default node index.js

true
false

--jeroen

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.