Attention passengers: Flight 0703 is also known as Flight 451

I hate
octal.  Octal causes bugs.  I hate bugs, particularly stupid “gotcha” bugs.

C programmers do things like


int arr_flight
= 0703;


realizing that this does not assign the number 703, but rather 7 x 64 + 3 = 451.


worse, JScript programmers do things like


var arr_flight
= 0708;

var dep_flight
= 0707;


realizing that the former is a decimal literal but the latter is an octal


in JScript it really is the case that if a literal begins with 0, consists of only
digits and contains an 8 or a 9 then it is decimal but if it contains no 8 or 9 then
it is octal!  The first version of the JScript lexer did not implement those
rules, but eventually we changed it to be compatible with Netscape’s implementation.


is in keeping with the design principle that I mentioned earlier, namely “Got a
problem? Muddle on through!”
  However, since this problem can be caught at
compile time
, I think that the decision to make illegal octal literals into decimals
was a poor one.


just a mess. Octal literals and escape sequences have been removed from the ECMAScript
specification, though of course they live on in actual implementations for backwards


is why I added code to JScript .NET so that any use of an integer decimal or octal
literal that begins with zero yields a compiler warning, with one exception.
Obviously x
= 0; does
not produce a warning!

Tags JScript JScript .NET Scripting

Comments (5)

You must be logged in to post a comment.

  1. Jack ShainskyActually, not always the problem can be caught at compile time. If server generates pages with JS dynamically, the number containing 8 or 9 can appear in actual script once in a while. So the decision to correct the problem on the fly is not so bad as it seems.
  2. Log in to Reply
  3. October 23, 2003 at 4:47 pm
  4. Eric LippertWell, sure, but an ASP page could also generate a JScript block full of unterminated strings, and we catch those at compile time.
  5. Log in to Reply
  6. October 23, 2003 at 5:10 pm
  7. Kim Gräsman“This is why I added code to JScript .NET so that any use of an integer decimal or octal literal that begins with zero yields a compiler warning”Log in to Reply
  8. Out of curiosity: How does the warning manifest itself? A callback to the script host? Or is JScript.NET not part of the whole Active Scripting family?
  9. October 24, 2003 at 9:27 am
  10. Eric LippertCorrect — JScript .NET does not participate in the old, 20th century unmanaged Windows Script interfaces. Rather, it uses the IVSA, aka “Script for the .NET Framework” interfaces.JScript .NET has some super-cool error recovery mechanisms for IVSA scenarios — I might blog about them later, or convince Peter to.
  11. Log in to Reply
  12. One of the shortcomings of the old Windows Script interfaces was that there was no way to surface warnings, only errors. IVSA provides a more fully-fledged compiler hosting mechanism.
  13. October 24, 2003 at 6:14 pm
  14. Fabulous Adventures In CodingLog in to Reply
  15. July 29, 2004 at 2:47 pm

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s