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?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges