JavaScript toLowerCase(): Convert a String to Lowercase

The JavaScript toLowerCase() method converts a specified string to lowercase. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

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

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

      let myLowerString = myString.toLowerCase();
      document.getElementById("xyz").innerHTML = myLowerString;
   </script>
   
</body>
</html>
Output

In the above example, the first statement or the code declares a variable myString and assigns it a string value, "JavaScript is Fun. Is not it?".

Then, the toLowerCase() function is called on the myString variable to convert all the characters to lowercase. The result is stored in the myLowerString variable.

Finally, the code sets the innerHTML property of an HTML element with the ID of xyz to the value of myLowerString, which will display the converted string in all lowercase letters in the HTML page.

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

JavaScript toLowerCase() syntax

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

string.toLowerCase()

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

Advantages of the toLowerCase() function in JavaScript

Disadvantages of the toLowerCase() function in JavaScript

JavaScript Online Test


« Previous Tutorial Next Tutorial »


Liked this post? Share it!