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?
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.
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)
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).
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 (").
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With