es6-features
es6-features copied to clipboard
ES6 astral-plane unicode support
"Astral plane" characters (those whose code point value >= 0x10000) are supported in ES6 in the following ways:
- Iteration over strings correctly produces the code point -
console.log(...'a😬c')
logs"a" "😬" "c"
, whereasvar str = 'a😬c'; for (var i = 0; i < str.length; i++) { console.log(str[i]) }
logs"a" "�" "�" "c"
. - In that vein,
[...'a😬c'].length
is the correct value of 3, rather than'a😬c'.length
's incorrect value of 4. -
String.codePointAt()
lets you receive the correct code point -'a😬c'.codePointAt(1)
is'😬'
, but'a😬c'[1]
is'�'
.