Last active
March 12, 2021 08:59
-
-
Save armanozak/7ae2feeacd45383ffd7a2a5704643fd9 to your computer and use it in GitHub Desktop.
[Unicode Escape Sequences & Code Point Escapes] How they can be used as identifiers in JavaScript #javascript #tip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Unicode escape sequences & code point escapes | |
* can be used as identifiers in JavaScript... | |
*/ | |
const obj1 = { x: 'x' } | |
console.log( obj1.\u0078 ) // 'x' | |
const obj2 = { x: 'still x' } | |
console.log( obj2.\u{78} ) // 'still x' | |
const obj3 = { 愛: 'Love' } | |
console.log( obj3.\u611B ) // 'Love' | |
const obj4 = {} | |
obj4.\u611B = 'Love' | |
console.log( obj4 ) // { 愛: 'Love' } | |
const \u611B = 'Love' | |
console.log( 愛 ) // 'Love' | |
const \u5e73\u548c = 'Peace' | |
console.log( 平和 ) // 'Peace' | |
/* | |
* ...unless they represent an invalid identifier. | |
*/ | |
const \u20ba = '₺' // Uncaught SyntaxError | |
const \u{69}\u{66} = 'if' // Uncaught SyntaxError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment