Home > Article > Web Front-end > Detailed explanation of 4 functions for javascript letter case conversion_javascript skills
Four js functions are mainly used to implement letter case conversion in js:
1.toLocaleUpperCase
2.toUpperCase
3.toLocaleLowerCase
4.toLowerCase
The following is a simple analysis of these four js functions that implement case conversion.
1.toLocaleUpperCase
Converts all alphabetic characters in the string to uppercase, adapting to the current locale of the host environment.
2.toUpperCase
Converts all letters in the string to uppercase letters.
3.toLocaleLowerCase
Converts all alphabetic characters of the string to lowercase, taking into account the current locale of the host environment.
4.toLowerCase
Converts the letters in the string to lowercase letters.
The usage of the above four functions is basically the same. The following only uses toLowerCase as an example:
or:
We can see that toLocaleUpperCase and toUpperCase have the same function, toLocaleLowerCase and toLowerCase also have the same function, so what is the difference between them?
(1) toLocaleUpperCase toLocaleLowerCase These two functions will adapt to the current locale of the host environment when converting characters in a string. In most cases, the result is the same as using the toUpperCase toLowerCase functions. But if the language rules conflict with regular Unicode case mapping, the results will be different.
(2) toUpperCase toLowerCase method does not convert non-alphabetic characters in the string.