Skip to content

Commit

Permalink
js-quirks: Mention annex B.1.1 (legacy octal integer literals).
Browse files Browse the repository at this point in the history
  • Loading branch information
jorendorff committed Oct 25, 2019
1 parent 53c2f74 commit f60f293
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions js-quirks.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ in this section is easy to deal with, but #4 is special.
For another ambiguity, see "Slashes" below.


### Legacy octal literals (*)

This is more funny than difficult.

In a browser, in non-strict code, every sequence of decimal digits (not
followed by an identifier character) is a *NumericLiteral* token.

If it starts with `0`, with more digits after, then it's a legacy Annex
B.1.1 literal. If the token contains an `8` or a `9`, it's a decimal
number. Otherwise, hilariously, it's octal.

```
js> [067, 068, 069, 070]
[55, 68, 69, 56]
```

This comment has been minimized.

Copy link
@mathiasbynens

mathiasbynens Apr 27, 2020

Do you want to mention string literals as well?

'\07' === '\x07', but '\08' === '\x008' since 8 is not an octal digit, and '\0' looks like an octal escape but isn't. But still, '\08' is considered a legacy octal escape sequence, and is thus disallowed in strict mode, or even in sloppy mode within template literals. Not confusing at all :)

This comment has been minimized.

Copy link
@jorendorff

jorendorff Apr 27, 2020

Author Contributor

Terrific.

I'm not able at the moment to see why the \0 in '\0' does not match two different EscapeSequence productions when B.1.2 is included. The grammar seems ambiguous to me.

This comment has been minimized.

Copy link
@jorendorff

jorendorff Apr 27, 2020

Author Contributor

Oh, the two productions never both exist. The normal rule that matches '\0' is removed by the "extension". (crumples up computer, throws it in the trash)

This comment has been minimized.

Copy link
@jorendorff

jorendorff Apr 27, 2020

Author Contributor


### Strict mode (*)

*(entangled with: lazy compilation)*
Expand Down

0 comments on commit f60f293

Please sign in to comment.