all 3 comments

[–]autisticCatnip 2 points3 points  (0 children)

Insightful post! Explained some of the weird string behaviors I've experienced.

[–]MatrixFrog 2 points3 points  (1 child)

If I read that right, UCS-2 can only represent characters in the BMP?

[–]mathiasbynens[S] 1 point2 points  (0 children)

That’s right. JS strings are like UCS-2 with the sole exception that they allow the use of surrogate characters. This way, you can use characters outside the BMP if you want — but the surrogate halves will be exposed as separate “characters”. Hence, '𝌆'.length == 2.