While browsing through the MDN documentation on charAt, I came across a question about the UTF-16 encoding of strings in JavaScript.
To test my understanding, I decided to run this script in NodeJS:
Buffer.from("€").length // returns 3
I was puzzled by the result showing 3 bytes. Typically, I would expect either 2 or 4 bytes for UTF-16 strings. How is it possible for a UTF-16 string to be 3 bytes long?
Although I searched various questions on StackOverflow, I couldn't find a satisfactory explanation for this particular issue.