I started reading JavaScript: The Good Parts book and became confused at first pages (7 and 9 if be exact) by the railroad diagrams.
There are diagrams for the name
JavaScript literal names may start with letters, digits, underscores, or dollar signs. However, it's a convention to use only letters as the first character. http://javascript.crockford.com/code.html
The string literal may have any escaped character (e.g. "\""
or "\\"
) or any other character save the delimiter ("
or '
) and the backslash (\
). The escaped character is not a single backslash. It's the representation of the whole escaped character. See the escaped character rail diagram in your own link.
It looks like the name railroad diagram definitely has problems. As you say, a name can start with underscore, but the diagram precludes it, and dollar signs seem to be completely missing.
You're wrong about the string literals though, since "\"
is properly not allowed.
One for you, one for Crockford.
The language described in the book "The Good Parts" is not JavaScript but a subset of it - you can call it "Crockford's JavaScript". Crockford introduces new syntax restrictions. One of those restrictions is that names cannot start with $
or _
.