Is it ever possible that
string.length !== string.toLowerCase().length?
I know it is possible for
toUpperCase, given the answers at Change to .length with toUpperCase?, but I don’t know whether it’s possible for
Yes, it’s possible, not all case mappings are one to one as you’ve seen when going from lowercase to uppercase, the same can apply when going from uppercase to lowercase, for example:
const char = "İ"; const charLower = char.toLowerCase(); console.log(char, char.length); // İ 1 console.log(charLower, charLower.length); // i̇ 2 console.log(char.length !== charLower.length); // true
There is a note in the specification that also highlights this behavior at section 22.214.171.124:
The case mapping of some code points may produce multiple code points. In this case the result String may not be the same length as the source String