Javascript String toUpperCase()

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

Example

const message = "javascript is fun";

// convert message to uppercase const upperMessage = message.toUpperCase();
console.log(upperMessage); // Output: JAVASCRIPT IS FUN

toUpperCase() Syntax

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.


toUpperCase() Return Value

  • 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.

Also Read:

Did you find this article helpful?

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community