Last updated on February 20, 2023
The toUpperCase() method converts the string into uppercase. For example, if the string is javascript then the toUpperCase() method would return JAVASCRIPT. It doesn’t accept any parameter and can be accessed through do notation.
Syntax
anyTextOrString.toUpperCase()
Parameter
It doesn’t need any parameter, it attaches directly to a string that needs to be converted.
Example 1
Let’s create a string that should contain a lowercase value,
"javascript"
Next, attach the toUpperCase() method to convert it into uppercase.
"javascript".toUpperCase();
// Output: JAVASCRIPT
In this example, the toUpperCase() method is attached to the string that converts it into uppercase. You can use the console.log() function to print the result in the console.
console.log("javascript".toUpperCase());
Example 2
Create a variable with the let keyword and assign a lowercase string value to it.
let favoriteColor = "black";
In the next line, attach the toUpperCase() method to the variable with the dot.
favoriteColor.toUpperCase()
// Output: BLACK
It converts the variable’s value to uppercase, and in the output, we get the converted value. You can print the converted value in the console through the below example,
console.log(favoriteColor.toUpperCase());