totn JavaScript

JavaScript: String toLocaleLowerCase() method

This JavaScript tutorial explains how to use the string method called toLocaleLowerCase() with syntax and examples.

Description

In JavaScript, toLocaleLowerCase() is a string method that is used to convert a string to lowercase based on locale. Because the toLocaleLowerCase() method is a method of the String object, it must be invoked through a particular instance of the String class.

Syntax

In JavaScript, the syntax for the toLocaleLowerCase() method is:

string.toLocaleLowerCase([locale]);

Parameters or Arguments

locale
Optional. It is a BCP 47 language tag or an array of such tags. A BCP 47 language tag defines a language that may contain a primary language code as well as an extension. If this parameter is not provided, the toLocaleLowerCase() method will use the host environment's current locale.

Returns

The toLocaleLowerCase() method returns a string converted to lowercase using a specific locale.

Note

  • The toLocaleLowerCase() method does not change the value of the original string.

Example

Let's take a look at an example of how to use the toLocaleLowerCase() method in JavaScript.

For example:

var totn_string = 'TechOnTheNet';

console.log(totn_string.toLocaleLowerCase());

In this example, we have declared a variable called totn_string that is assigned the string value of 'TechOnTheNet'. We have then invoked the toLocaleLowerCase() method of the totn_string variable to convert the string to lowercase.

We have written the output of the toLocaleLowerCase() method to the web browser console log, for demonstration purposes, to show what the toLocaleLowerCase() method returns.

The following will be output to the web browser console log:

techonthenet

In this example, the toLocaleLowerCase() method used the host's current locale and converted the string 'TechOnTheNet' to lowercase and returned a string value of 'techonthenet'.

Specifying a Locale Parameter

Instead of using the host's current locale, you can also specify a BCP 47 language tag for the locale parameter that will be used to convert the string to lowercase.

For example:

var totn_string = 'CAFÉ';

console.log(totn_string.toLocaleLowerCase('en-US'));

The following will be output to the web browser console log:

café

In this example, the toLocaleLowerCase() method used a locale parameter of 'en-US' to convert the string to lowercase using US English. The toLocaleLowerCase() method returned a string value of 'café'.