hc ch
hc ch

Reputation: 137

What's the difference between \u0061, \x61 and \141 in Javascript

enter image description here

Why the first expression can be executed without error , but the second and the third one can not be executed?

Upvotes: 1

Views: 543

Answers (1)

deceze
deceze

Reputation: 522412

The spec allows it:

Unicode escape sequences are permitted in an IdentifierName, where they contribute a single Unicode code point to the IdentifierName. The code point is expressed by the CodePoint of the UnicodeEscapeSequence (see 11.8.4). The \ preceding the UnicodeEscapeSequence and the u and { } code units, if they appear, do not contribute code points to the IdentifierName. […]

https://tc39.github.io/ecma262/#sec-names-and-keywords

In other words, you can use \u.... escape sequences as replacement for literal characters for identifiers (such as console). The same allowance is not made for other kinds of escape sequences like \x...

Upvotes: 3

Related Questions