Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point of unicode escape sequences in identifier names in JavaScript?

JavaScript allows for having unicode escape sequences in identifier names... for example:

var \u0160imeVidas = "blah";

The above variable starts with the (croatian) letter Š, so that the complete name of the variable is "ŠimeVidas". Now, this is neat, but what's the point? Is there any scenario where this feature may be of any use?

like image 913
Šime Vidas Avatar asked Sep 03 '10 22:09

Šime Vidas


People also ask

What is Unicode escape sequence?

A unicode escape sequence is a backslash followed by the letter 'u' followed by four hexadecimal digits (0-9a-fA-F). It matches a character in the target sequence with the value specified by the four digits. For example, ”\u0041“ matches the target sequence ”A“ when the ASCII character encoding is used.

What are escape sequences in JavaScript?

Javascript uses '\' (backslash) in front as an escape character. To print quotes, using escape characters we have two options: For single quotes: \' (backslash followed by single quote) For double quotes: \” (backslash followed by double quotes)

What is the Unicode in JavaScript?

Unicode is a universal character set that defines the list of characters from the majority of the writing systems, and associates for every character a unique number (code point).

What is the use of escape sequence U?

Escape sequences are typically used to specify actions such as carriage returns and tab movements on terminals and printers. They are also used to provide literal representations of nonprinting characters and characters that usually have special meanings, such as the double quotation mark (").


1 Answers

Let’s say you’ve got a library stored in UTF-8 and that the author choose to use non-ASCII characters in the APIs. Then, let’s say that—for some reason—you need to access this library from a file stored in ASCII. Allowing the Unicode escape sequences in identifiers allows you to do that. There could be other such scenarios, but that’s one example.

like image 187
Robert Fisher Avatar answered Sep 26 '22 16:09

Robert Fisher