Skip to content
the poor coder

tolowercase javascript

Poor Man
Published
Reading time
2 min read
On this page

Converting Text to Lowercase in JavaScript#

If you want to convert text to lowercase in JavaScript, you can use the toLowerCase() method. This method returns the calling string value converted to lowercase.

Example:#

Text
var text = "HELLO WORLD";
var lowercaseText = text.toLowerCase();

console.log(lowercaseText); // Output: hello world

In the above example, we created a variable text and assigned it a string value "HELLO WORLD". Then we used the toLowerCase() method to convert this string to lowercase and assigned it to a new variable lowercaseText. Finally, we printed out the value of lowercaseText using console.log().

You can also use the toLowerCase() method directly on a string literal:

Text
console.log("HELLO WORLD".toLowerCase()); // Output: hello world

This will directly return the lowercase version of the string.

Another way to convert text to lowercase is by using the toLocaleLowerCase() method. This method returns a string where all alphabetic characters have been converted to lowercase, taking into account the host environment's current locale.

Example:#

Text
var text = "ß";
var lowercaseText = text.toLocaleLowerCase();

console.log(lowercaseText); // Output: ss

In the above example, we created a variable text and assigned it a string value "ß". Then we used the toLocaleLowerCase() method to convert this string to lowercase, taking into account the current locale. Finally, we printed out the value of lowercaseText using console.log().

Code:#

Text

var text = "HELLO WORLD";
var lowercaseText = text.toLowerCase();

console.log(lowercaseText);

console.log("HELLO WORLD".toLowerCase());

var text = "ß";
var lowercaseText = text.toLocaleLowerCase();

console.log(lowercaseText);

In the above code, we declared a variable text and assigned it a string value "HELLO WORLD". Then we used the toLowerCase() method to convert this string to lowercase and assigned it to a new variable lowercaseText. Finally, we printed out the value of lowercaseText using console.log(). We also used the toLocaleLowerCase() method to convert a string containing a german character "ß" to lowercase and printed it out using console.log().

The code is also highlighted using the highlight.js library for better readability.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC