DEV Community

Kulsum Shaikh
Kulsum Shaikh

Posted on • Edited on

1

.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:

StringOne.toLowerCase()
Enter fullscreen mode Exit fullscreen mode

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

console.log(stringOne);
console.log(stringOne.toLowerCase());
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!

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay