JavaScript toUpperCase(): Convert a String to Uppercase

The JavaScript toUpperCase() method converts a specified string to uppercase. For example:

HTML with JavaScript Code
<!DOCTYPE html>

   <p id="xyz"></p>

      let myString = "JavaScript is Fun. Is not it?";

      let myUpperString = myString.toUpperCase();
      document.getElementById("xyz").innerHTML = myUpperString;

The code starts with the declaration of an empty HTML paragraph element with the ID "xyz."

In the script section, a string variable "myString" is declared and assigned the value "JavaScript is Fun. Is not it?".

The next line creates another variable, myUpperString, which contains the uppercase version of "myString" using the built-in toUpperCase() method. This method converts all the lowercase characters in the string to uppercase characters.

Finally, the content of the HTML paragraph element with the ID "xyz" is set to the value of "myUpperString" using the innerHTML property of the document object. This means that the text "JAVASCRIPT IS FUN. IS NOT IT?" will be displayed in the paragraph element when the page is loaded.

That is, all the lowercase characters of the specified string will be converted into their uppercase equivalent.

JavaScript toUpperCase() syntax

The syntax of the toUpperCase() method in JavaScript is:


The toUpperCase() method does not change the original string. Rather, it returns a new string that is the exact copy of the original string, except that, all characters will be in uppercase.

Advantages of the toUpperCase() function in JavaScript

Disadvantages of the toUpperCase() function in JavaScript

JavaScript Online Test

« Previous Tutorial Next Tutorial »

Liked this post? Share it!