Javascript String toUpperCase()

The JavaScript String toUpperCase() method returns the string converted to uppercase.

The syntax of the toUpperCase() method is:

str.toUpperCase()

Here, str is a string.


toUpperCase() Parameters

The toUpperCase() method does not take in any parameters.


Return value from toUpperCase()

  • Returns a new string representing the calling string converted to uppercase.

Notes:

  • The toUpperCase() method raises TypeError when called on null or undefined.
  • The toUpperCase() method does not change the original string.

Example: Using toUpperCase() method

let str = "Hello World!";
let sentence = "Java is to JavaScript what Car is to Carpet.";

let uppercase_str = str.toUpperCase();
console.log(uppercase_str); // HELLO WORLD!

let uppercase = sentence.toUpperCase();
console.log(uppercase); // JAVA IS TO JAVASCRIPT WHAT CAR IS TO CARPET.

Output

HELLO WORLD!
JAVA IS TO JAVASCRIPT WHAT CAR IS TO CARPET.

Recommended Reading: JavaScript String toLowerCase()