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 raisesTypeError
when called onnull
orundefined
. - 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: