2 ms·
IIRC from some other article; most JavaScript engines use a UTF-16 Unicode encoding for characters, and it looks like the .length attribute is reporting the mem
by mjevans 7y ago
IIRC from some other article; most JavaScript engines use a UTF-16 Unicode encoding for characters, and it looks like the .length attribute is reporting the memory footprint in terms of 16 bit codepoints. A single grapheme (display 'character', pictograph, or fixed sized space) may be composed of one or more codepoints.
'length' is subjective. It makes sense to want to know how many storage units are required.
Knowing the number of printed 'graphemes' (do we count non-printing 'characters'?) might also be useful.
The display length (at a given scaling size, taking in to consideration font kerning/etc) can also be useful.
That's where the linked article really goes off the rails. Characters don't have printing widths, not outside of extremely specific circumstances. You have to ask the layout engine in use what dimensions are occupied after it solves the very complex problem.