JS: Unicode Escape Sequence

By Xah Lee. Date: . Last updated: .

Unicode Escape Sequence

Character in string can be represented by a escape sequence.

\u{hexadecimal}
represent any character whose Codepoint is the Hexadecimal

(new in ES2015)

// represent any character by their Codepoint
console.log("\u{41}" === "A");

// if 0 padded, still works
console.log("\u{000000000041}" === "A");

// any unicode char works
console.log("\u{3b1}" === "Ξ±");
console.log("\u{1f602}" === "πŸ˜‚");
// unicode escape can be used in identifiers

// deno-fmt-ignore
const \u{3b1} = 123;

console.log(Ξ±);
// 123
\u4_hexa_digits
represent a character whose Codepoint can be represented by 4 Hexadecimal digits or less. Must pad 0 in front if not 4 digits
// represent a char by its codepoint in hexadecimal
// must pad 0 in front if not 4 digits
console.log("\u0041" === "A");
console.log("\u03b1" === "Ξ±");

Where Can Unicode Escape Sequence be Used

Unicode escape sequence can be used in:

Within a comment, Unicode escape sequence is ignored.

JavaScript, String