In ES6, when we use codePointAt(0)
on a string with one character in it ('') that has a Unicode code point value larger than U+FFFF (therefore not part of the Basic Multilingual Plane), we get the code point 134071. The string still actually has two code points in it, that represent this 134071 value.
> (55362).toString(16)
'd842'
> (57271).toString(16)
'dfb7'
> "\ud842\udfb7"
''
> const j = "\ud842\udfb7"
undefined
> j
''
> j.codePointAt(0)
134071
> j.codePointAt(1)
57271
>
My question is how do we go from the two code points 55362 and 57271 to the single code point 134071. I am talking about the mathematical relationship here.
Also, why can we still get access to the code point at position 1, but we can't get access to the individual code point at position 0?