The toLowerCase()
method returns the string converted to lowercase.
Example
const message = "JAVASCRIPT IS FUN";
// convert message to lowercase
const lowerMessage = message.toLowerCase();
console.log(lowerMessage);
// Output: javascript is fun
toLowerCase() Syntax
The syntax of the toLowerCase()
method is:
str.toLowerCase()
Here, str is a string.
toLowerCase() Parameters
The toLowerCase()
method does not take in any parameters.
toLowerCase() Return Value
- Returns a new string representing the calling string converted to lowercase.
Notes:
- The
toLowerCase()
method raisesTypeError
when called onnull
orundefined
. - The
toLowerCase()
method does not change the original string.
Example: Using toLowerCase() method
let str = "Hello World!";
let sentence = "Java is to JavaScript what Car is to Carpet.";
let lowercase_str = str.toLowerCase();
console.log(lowercase_str); // hello world!
let lowercase = sentence.toLowerCase();
console.log(lowercase); // java is to javascript what car is to carpet.
Output
hello world! java is to javascript what car is to carpet.
Also Read: