JavaScript: good part / line rail charts confusing

I started reading JavaScript: the book "Good Details" and got confused on the first pages (more precisely, 7 and 9) on the railway schemes.

There are charts for the name and string literal. (you can see the diagrams here )

As I know, names in JavaScript can begin with letters, as well as with an underscore or even β€œ$”. Following the diagram of a book, it can only begin with letters.

For a string literal, imagine that you want to represent the string as follows: "\\".
Following the diagram, this is not possible (it seems that after the "escaped character" is required "any unicode character except" and \ and contol ".

Are these errors in the book? Or am I missing something?

+4
source share
3 answers

The language described in The Good Details is not JavaScript, but a subset of it β€” you can call it Crockford JavaScript. Crockford introduces new syntactic restrictions. One of these limitations is that names cannot begin with $ or _ .

+5
source

It seems that the name of the railway definitely has problems. As you say, a name may begin with an underscore, but the chart excludes it, and the dollar signs seem to be completely absent.

You are mistaken in string literals, since "\" not allowed.

One for you, one for Crockford.

+1
source

JavaScript letter names can begin with letters, numbers, underscores, or dollar signs. However, this agreement uses only letters as the first character. http://javascript.crockford.com/code.html

A string literal can have any escaped character (for example, "\"" or "\\" ) or any other character that preserves the delimiter ( " or ' ) and backslash ( \ ). An escaped character is not a single backslash. This is a representation of the entire runaway character. See the Rail Chart of the escaped character in your own link.

+1
source

Source: https://habr.com/ru/post/923506/


All Articles