Unicode Escapes: \uXXXX Notation
You'll learn how to represent any character from any language using a special four-digit hexadecimal code.
What Are Unicode Escapes?
In the previous lesson, you learned about escape sequences like \n and \t. Unicode escapes take this idea further: they let you represent any Unicode character using its unique code point, written as \uXXXX where each X is a hexadecimal digit (0-9, A-F).
Think of Unicode as a massive international phone book where every character—from English letters to Chinese symbols to emoji—has a unique number. The \u notation is your way of dialing that number directly.
The Format
The pattern is always: backslash, lowercase u, followed by exactly four hexadecimal digits.
For example:
\u0041represents the letter 'A'\u0048represents the letter 'H'\u20ACrepresents the Euro symbol '€'\u4E2Drepresents the Chinese character '中'
When to Use Unicode Escapes
You might use Unicode escapes when:
- Your keyboard can't type a specific character
- You need to ensure a character appears correctly regardless of file encoding
- You're documenting exactly which character you mean
Example with char Variables
char letterA = '\u0041'; // Same as 'A'
char heart = '\u2665'; // Heart symbol ♥
char chineseChar = '\u4E2D'; // Chinese character 中
All three variables hold valid char values, just expressed using their Unicode code points instead of typing the symbols directly.
Key Takeaway: The \uXXXX notation lets you represent any Unicode character using its four-digit hexadecimal code point, giving you access to thousands of characters beyond your keyboard.