Note that, this method does not affect any of the special characters, digits, and string characters that are already in uppercase.
The following syntax represents the string.toUpperCase() method:
- a string that you want to convert to upper case.
- toUpperCase() is a method, which is used to convert string characters into upper case characters.
Let’s take a look at the example:
How to convert a string to uppercase characters, which is stored in an array?. You can see the following example:
Note that, This method throws an exception if you call with
TypeError: Cannot read property ‘toLowerCase’ of undefined
In case, you pass the undefined string into toUpperCase() method and then you will get some error. The error looks like this: TypeError: Cannot read property ‘toLowerCase’ of undefined.
The following example:
let str = undefined let res = str.toUpperCase(); console.log(res) // TypeError: Cannot read property ‘toLowerCase’ of undefined.
In the above mention, this method does not affect any of the special characters, digits, and string characters that are already in uppercase. See the following example for that:
let str = 'It iS a [email protected]@$$t Day.' let string = str.toUpperCase(); console.log(string); //IT IS A [email protected]@$$T DAY.