How do you transform a string to all uppercase letters in JavaScript?

The toUpperCase() method converts a string to all uppercase letters in JavaScript. It doesn't change anything else about the original string, doesn't take any parameters, and is applied to all the letters in a given string.

In this article, we'll give you a quick rundown on how to use it!

Here's a code example:

    
      const yourString = "Dogs are better than cats."

      yourString.toUpperCase()
      // output: "DOGS ARE BETTER THAN CATS."
    
  

As you can see, the toUpperCase() method returns the value of the string but in all uppercase.

Here's another example, but with an original string that has a wide mix of lowercase and uppercase letters in it:

    
      const yourString = "DoGs aRe BEttER than CATS."

      yourString.toUpperCase()
      // output: "DOGS ARE BETTER THAN CATS."
    
  

You should see that it works the same as before, regardless of how many lowercase letters are in the string or where they are located.

This method is supported in all browsers and even works all the way back to IE6.

We also have an article on how to use the toLowerCase() method.

Thanks for reading!