Converting characters from lower case to upper case is non-trivial if you want to support anything other than the English letters a
through z
. There are mappings involved in the Unicode database.
So toUpperCase
is the right tool for this job. According to the spec, it uses the Unicode database to select the appropriate upper case character. (That link is to toLowerCase
because toUpperCase
just says it does the same thing as toLowerCase
, but for upper case.)
But if you only supported the English letters a
through z
, those are represented by character codes 97 through 122, inclusive. A
through Z
are represented by character codes 65 through 90, inclusive. So:
var upperChar = String.fromCharCode(lowerChar.charCodeAt(0) - 32);
would do it. But I strongly recommend not doing that.
solved How do I change a letter from lowercase to uppercase without using toUppercase? [closed]