Add new comment

#7 Unicode - Lessons Learned While Reading "Effective Javascript"

In JavaScript, strings consist of 16-bit code units (not code points). Characters that you wish to represent which are outside of the Base Multilingual Plane must be represented using surrogate pairs. A small quirk to be aware of in these cases, is because JS is using code-units, you'll sometimes get some unexpected results which operations such as string length or charAt:

Although it seems very unlikely that you'll have playing cards in your strings, it *may* happen that a slightly esoteric character set from an unexpected language - in which case, knowing this quirk may save you some pain in the future!