javascript
  1. javascript-tolocalelowercase

JavaScript toLocaleLowerCase()

The toLocaleLowerCase() method in JavaScript is used to convert a string to lowercase letters based on the host's current locale. This method does not change the original string, but it returns a new string.

Syntax

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

string.toLocaleLowerCase([locale])

Here, string is the string to be converted, and locale is an optional parameter that specifies the locale to use.

Example

The following example demonstrates how to use the toLocaleLowerCase() method in JavaScript:

let str = 'HELLO WORLD';
console.log(str.toLocaleLowerCase()); // Output: hello world

In this example, the toLocaleLowerCase() method is used to convert the str variable to lowercase.

Output

The output of the above example would be:

hello world

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>JavaScript Output</title>
</head>
<body>

<!-- Your JavaScript code goes here -->
<script>
  let str = 'HELLO WORLD';

  // Using the toLocaleLowerCase method to convert the string to lowercase
  let lowerCaseStr = str.toLocaleLowerCase();

  // Displaying the result in the HTML document
  document.write('<p>' + lowerCaseStr + '</p>');
</script>

</body>
</html>

Try Playground

Explanation

The toLocaleLowerCase() method converts a string to lowercase based on the host's current locale. This method returns a new string and does not modify the original string. If the locale parameter is not provided, then the method uses the default locale of the host environment.

Use

The toLocaleLowerCase() method is used to convert uppercase characters in strings to lowercase characters. This method is helpful when we need to compare strings or search for strings in a case-insensitive manner.

Important Points

  • The toLocaleLowerCase() method does not modify the original string.
  • The locale parameter is an optional parameter and if it is not specified, then the method uses the default locale of the host environment.
  • This method is case-insensitive.
  • This method does not change the case of non-alphabetic characters.

Summary

The toLocaleLowerCase() method in JavaScript is a useful method for converting uppercase characters to lowercase characters based on the host's current locale. It returns a new string and does not modify the original string. This method is helpful when we need to compare strings in a case-insensitive manner or search for strings.

Published on: