JavaScript toLowerCase() is a built-in String prototype function that returns a new string with all alphabetic characters converted to lowercase based on the host environment’s current locale configuration.
let str = "Cristiano Ronaldo is a Portuguese professional footballer"; lowerStr = str.toLowerCase(); console.log(lowerStr); // Output: cristiano ronaldo is a portuguese professional footballer
Strings are immutable, so it does not modify the original string. It raises TypeError if you attempt to call on null or undefined.
Syntax
string.toLowerCase()
Parameters
None: It does not take any arguments.
String with all uppercase letters

let single_str = "CRISTIANO"; lower_single_str = str.toLowerCase(); console.log(lower_single_str); // Output: cristiano
Mixed cases with numbers and special characters
If a string contains uppercase, lowercase, numbers, and special characters, the toLowerCase() method does not change already lowercase characters, numbers, and special characters.
let mixed_str = 'Cristiano Ron@ldo CR7'; mixed_lowercase = mixed_str.toLowerCase(); console.log(mixed_lowercase); // Output: cristiano ron@ldo cr7
As you can see from the output, it only affects alphabetic characters, so digits and special characters remain unchanged.
Converting all strings of the array to lowercase
To convert an array of strings to lowercase, use the combination of array.map() and string.toLowerCase() methods.
let array_of_strings = [ 'MILLIE', 'NOAH', 'FINN', 'SADIE' ] let lower_case_array = array_of_strings.map((str) => str.toLowerCase()) console.log(lower_case_array) // Output: [ 'millie', 'noah', 'finn', 'sadie' ]
In this code, we used an array.map() function that transforms an array of elements from uppercase to lowercase using the str.toLowerCase() and returns a new array containing all the lowercase elements.
Unicode characters
When you pass unicode characters like accented letters, it converts these letters to lowercase, but it does not always follow the locale-specific rules.
unicode_str = "ÄÖÜ"; lower_unicode_str = unicode_str.toLowerCase(); console.log(lower_unicode_str); // Output: äöü
Locale-specific conversion
When it comes to proper locale-specific translation (like Turkish dotted/undotted i or some Greek letters), the toLocaleLowerCase() method ensures the proper casing according to the given language.
The toLowerCase() function is not the correct function to do the job in this scenario.
const str = "Istanbul İZMİR";
// Turkish locale lowercase
console.log(str.toLocaleLowerCase('tr'));
// Output: ıstanbul izmir
// Default (English-style) lowercase
console.log(str.toLowerCase());
// Output: istanbul i̇zmi̇r
You can see that both methods are returning different outputs.
TypeError: number.toLowerCase is not a function
If you apply the toLowerCase() method on Numbers (Other than string objects), it throws TypeError: number.toLowerCase is not a function error.
const number = 1921 number_to_lower = number.toLowerCase() console.log(number_to_lower) // TypeError: number.toLowerCase is not a function
Type coercion
To prevent the toLowerCase is not a function type of error, you can convert that number object into a string object using the “toString()” method and then apply the toLowerCase() method.
const number = 1921 const bool = true console.log(number.toString().toLowerCase()) // Output: 1921 console.log(String(bool).toLowerCase()); // Output: true
In the above, we not only used a number but also a boolean value, converted both values to a string, and then converted the string to lowercase.
Since the number has digits, it is unchanged. Also, a boolean value is represented by “true”, so it does not change either.
TypeError: Cannot read properties of null
What if you apply a str.toLowerCase() method on a null value? Well, it throws TypeError: Cannot read properties of null error because null is not a string object. It fails immediately.
const obj = null; console.log(obj.toLowerCase()); // This will throw an error because obj is null // TypeError: Cannot read properties of null (reading 'toLowerCase')
const obj = null;
// To fix this, we can check if obj is string
if (typeof obj === 'string') {
console.log("Object is a string");
}
else {
console.log("Object is not a string");
}
// Output: Object is not a string
And we handled the possible error efficiently.




