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,
- We define a string variable
strwith the value'HELLO WORLD'. - We use the
toLowerCase()method to convert the string to lowercase. - The result is stored in the variable
lowerStr. - We log
lowerStrto the console using theconsole.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,
- We define a string variable
strwith the value'JavaScript'. - We use the
toLowerCase()method to convert the string to lowercase. - The result is stored in the variable
lowerStr. - We log
lowerStrto the console using theconsole.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,
- We define a string variable
strwith the value'Hello 123!'. - We use the
toLowerCase()method to convert the alphabetic characters to lowercase. - The result is stored in the variable
lowerStr. - We log
lowerStrto the console using theconsole.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.