JavaScript Tutorials

JavaScript String toLowerCase()
Syntax & Examples

String.toLowerCase() method

The toLowerCase() method of the String class in JavaScript returns the calling string value converted to lowercase.


Syntax of String.toLowerCase()

The syntax of String.toLowerCase() method is:

toLowerCase()

This toLowerCase() method of String returns the calling string value converted to lowercase.

Return Type

String.toLowerCase() returns value of type String.



✐ Examples

1 Using toLowerCase() method

In JavaScript, the toLowerCase() method converts a string to lowercase letters.

For example,

  1. We define a string variable str with the value 'HELLO WORLD'.
  2. We use the toLowerCase() method to convert the string to lowercase.
  3. The result is stored in the variable lowerStr.
  4. We log lowerStr to the console using the console.log() method.

JavaScript Program

const str = 'HELLO WORLD';
const lowerStr = str.toLowerCase();
console.log(lowerStr);

Output

hello world

2 Using toLowerCase() method on a string with mixed case

In JavaScript, the toLowerCase() method can be used to convert a string with mixed case letters to all lowercase letters.

For example,

  1. We define a string variable str with the value 'JavaScript'.
  2. We use the toLowerCase() method to convert the string to lowercase.
  3. The result is stored in the variable lowerStr.
  4. We log lowerStr to the console using the console.log() method.

JavaScript Program

const str = 'JavaScript';
const lowerStr = str.toLowerCase();
console.log(lowerStr);

Output

javascript

3 Using toLowerCase() method on a string with numbers and symbols

In JavaScript, the toLowerCase() method only affects alphabetic characters and leaves numbers and symbols unchanged.

For example,

  1. We define a string variable str with the value 'Hello 123!'.
  2. We use the toLowerCase() method to convert the alphabetic characters to lowercase.
  3. The result is stored in the variable lowerStr.
  4. We log lowerStr to the console using the console.log() method.

JavaScript Program

const str = 'Hello 123!';
const lowerStr = str.toLowerCase();
console.log(lowerStr);

Output

hello 123!

Summary

In this JavaScript tutorial, we learned about toLowerCase() method of String: the syntax and few working examples with output and detailed explanation for each example.