DEV Community

Kulsum Shaikh
Kulsum Shaikh

Posted on • Updated on

.toLowerCase() or not to Lowercase

.toLowerCase() is a method in JavaScript that is used to convert any string to lowercase. The return value for it is also a string.

There are many reasons as to why someone would need to use it. One example would be if someone has a search bar on their website. Since user input is unpredictable, we need to make sure we are handling the user input in the best way possible. We should convert the strings into one case which is why we were making it all lowercase. Doing that will ensure that the results will match the search.

Let’s look at how .toLowerCase() works!

First, lets declare a string with the name of stringOne:

const stringOne =  Lets see HOW .toLowerCase() Works
Enter fullscreen mode Exit fullscreen mode

Then, we will use the syntax for .toLowerCase() on this string:

Enter fullscreen mode Exit fullscreen mode

Finally, we can console.log the string with and without the new syntax to see the difference:

Enter fullscreen mode Exit fullscreen mode

Now, let's see what the console.log shows us:

Let’s see HOW .toLowerCase() Works
let’s see how .tolowercase() works
Enter fullscreen mode Exit fullscreen mode

If we did not have this method, we would have to manually parse the string using regular expressions. That would take a really long time!

Top comments (0)