Sometimes, we need to convert our string, into uppercase, and in such situations, we can make use of the toUpperCase() method.
This method is going to return a new string, converted to upper case. Remember that still, the original string is going to be as it was.
Let’s have a look at some of the examples, which give us an idea of the toUpperCase method –
As you can see, in the program, we have a string, and then we are calling the toUpperCase method for the string. Also, in the next instruction, we are printing the original string to the console.
Now, the toUpperCase method returns the modified string, converted to uppercase. Let’s have a look at the output now as well –
As you can see, the output comes out to be as desired. The toUpperCase method returned a new modified string, and the original string is as it was. We can use this method, as and when required.