JS: Unicode Character Escape Sequence
You can use escape sequences to represent Unicode char. For example,
"\u03b1" is the same as
\u and must be followed by 4 digits of hex.
It works for any Unicode whose codepoint is less than 65536 (that is, 2^16, 16 bits)
// Unicode escape sequence console.log ( "\u03b1" === "α"); // true // works for any Unicode whose codepoint is less than 65536 (that is, 2^16, 16 bits) // start with “\u” and must be followed by 4 digits of hexadecimal
Here's a example that does not work.
console.log ( "\u1f602" === "ὠ2" ); // true // 😂 // name: FACE WITH TEARS OF JOY // codepoint decimal: 128514 // codepoint hexadecimal: 1f602
Unicode escape sequence can be used in:
- string literals
- regular expression literals
- template literals
- any function that takes argument of Unicode code point can also be replaced by Unicode escape sequence.
Within a comment, Unicode escape sequence is ignored.
- JS: Source Code Encoding
- JS: String Code Unit vs Code Point
- JS: Unicode Character Escape Sequence
- JS: Allowed Characters in Identifier
- HTML: Allowed Characters in id Attribute
- HTML: Character Sets and Encoding
- HTML/XML Entity List
- JS: Template String
- JS: Convert String to Number
- JS: Encode URL, Escape String
- JS: Format Number
- JS: JSON
Ask me question on patreon