Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Javascript String toUpperCase()
In this tutorial, we will learn about the JavaScript String toUpper() method with the help of examples.
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 raisesTypeErrorwhen called onnullorundefined. - 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?