javascript
  1. javascript-tolowercase

JavaScript toLowerCase()

The toLowerCase() method in JavaScript is used to convert a string to lowercase letters. It returns the new string with all the letters in the original string converted to lowercase.

Syntax

The syntax for using the toLowerCase() method is as follows:

string.toLowerCase()

Here, string is the string that you want to convert to lowercase.

Example

Consider the following example:

let message = "Welcome to JavaScript World!";
let lowerCaseMessage = message.toLowerCase();
console.log(lowerCaseMessage);

The output of the above code will be:

welcome to javascript world!

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>toLowerCase() Method Example</title>
</head>
<body>

<!-- Display area for the output -->
<div id="output"></div>

<script>
    // Your JavaScript code
    let message = "Welcome to JavaScript World!";
    let lowerCaseMessage = message.toLowerCase();

    // Display the output in the HTML document
    document.getElementById('output').innerHTML = `
        <p>Original Message: "${message}"</p>
        <p>Message in Lowercase: "${lowerCaseMessage}"</p>
    `;
</script>

</body>
</html>

Try Playground

Explanation

The toLowerCase() method is called on a string and returns a new string with all the letters in the original string converted to lowercase. It does not modify the original string.

Use

The toLowerCase() method can be used when you want to convert a string to lowercase, such as when you are looking to compare case-insensitive strings or when you want to display text in a uniform case.

Important Points

  • The toLowerCase() method is case-insensitive, which means that it converts all uppercase letters to lowercase, and leaves lowercase letters unchanged.
  • It does not modify the original string, but instead, returns a new string with the converted lowercase letters.
  • The toLowerCase() method is Unicode aware and can handle non-ASCII characters.

Summary

The toLowerCase() method is a JavaScript string method that is used to convert a string to lowercase. It returns a new string with all the letters in the original string converted to lowercase. It can be helpful when you need to compare case-insensitive strings or display text in a uniform case.

Published on: