Is using a unicode escape sequence valid in the let
keyword?
Restating: Is the following code valid?
l\u0065t a = 1;
Is it equivalent to this code:
let a = 1;
Is using a unicode escape sequence valid in the let
keyword?
Restating: Is the following code valid?
l\u0065t a = 1;
Is it equivalent to this code:
let a = 1;
No.
ECMAScript does allow Unicode escape sequences in string literals, template literals and regex literals (so far so expected), and even in identifier names (more details). It does however not allow them in raw source text1, so they cannot form things such as keywords, other tokens and whitespaces.
(This has not changed since ES5. You also were not allowed, and continue to be not allowed, to use escape sequences in var
.)
1: One could of course imagine an implementation that interprets anything, including escape characters, to derive a source text2, but that would be a) weird and b) outside the scope of ECMAScript. Think of passing a string through JSON.parse
and eval
- such a string might as well contain l\u0065t
.
2: An actual example of something like this (where it actually makes sense) are HTML entities in a <script>
tag.