The toUpperCase() method is included in the string object and is fully supported in all browsers.
- mystring is the text you wish to change to upper case, and can be any string variable or value
- The original variable is not modified – the result of calling toUpperCase() will must be assigned to a new variable or used immediately
- Your text will be returned with all characters converted to upper case
- You can do the opposite with the toLowerCase() method – converting all characters to lowercase
To use toUpperCase(), call it from your existing string variable, and assign the result to a new variable:
var mystring = "abcdefg!"; var result = mystring.toUpperCase(); console.log(result); // "ABCDEFG!"
Converting the case of a string is frequently used when checking whether an email address or username is already in use in an authentication system, or comparing values in arrays. It’s also useful when formatting other user input for storage in a database.
Sometimes, you just want to make some text look REALLY LOUD – toUpperCase() does this effectively.