The toLowerCase() method in JavaScript is used to convert all the characters in a string to lowercase letters. Here's how it works:
Syntax: string.toLowerCase()
- string: The string you want to convert to lowercase.
Example:
let str = "HELLO, WORLD!";
let lowerCaseStr = str.toLowerCase();
console.log(lowerCaseStr); // Output: hello, world!
Explanation:
- We have a string str containing the text "HELLO, WORLD!" in uppercase.
- We use toLowerCase() to convert all the characters in the string to lowercase.
- The resulting string, "hello, world!", is stored in the variable lowerCaseStr and logged to the console.
Code Compiler Link: https://app.singhteekam.in/codecompiler/