To convert a string to uppercase in JavaScript, you can use the toUpperCase()
method of the String class.
In this example,
str1
with a string value of "Hello World"
.toUpperCase()
method of the string object str1
to convert it to uppercase and store the result in the variable upperCaseStr1
.toUpperCase()
method returns a new string with all characters converted to uppercase.upperCaseStr1
to the console using console.log()
.let str1 = "Hello World";
let upperCaseStr1 = str1.toUpperCase();
console.log("Uppercase of given string is: " + upperCaseStr1);
Uppercase of given string is: HELLO WORLD
In this example,
str2
with a string value of "apple"
.toUpperCase()
method of the string object str2
to convert it to uppercase and store the result in the variable upperCaseStr2
.toUpperCase()
method returns a new string with all characters converted to uppercase.upperCaseStr2
to the console using console.log()
.let str2 = "apple";
let upperCaseStr2 = str2.toUpperCase();
console.log("Uppercase of given string is: " + upperCaseStr2);
Uppercase of given string is: APPLE
In this tutorial, we learned How to convert String to Uppercase in JavaScript language with well detailed examples.