Nerd For Tech
Published in

Nerd For Tech

Basics of Javascript · String · toLowerCase() (method)

This article is a transcript of my free youtube series about basics of web development. If you prefer watching over reading, feel free to visit my channel “Dev Newbs”.

Hello there Dev Newbs! Method for the day will feel like a familiar one. That’s because we already covered its “locale” version. It is now time to take the older sister for a spin, too. Let’s get it over with.

toLowerCase() method converts a string to lowercase letters. The method does not change the original string.

Also this is one of the few methods that does not have any input parameters at all. How refreshing.

Return value of the method is a string, representing the value of an original string converted to lowercase.

Let’s have a look at some of the examples for basic usage in example 1.

const cities = "New York, Paris, Milan, Tokyo, ...";// use the method with variable containing string value
cities.toLowerCase() // new york, paris, milan, tokyo, ...
// use it directly with a string value
"ALPHABET".toLowerCase() // alphabet
// no lowercase - original value equals to converted value
let originalString = "hello there!";
let convertedString = originalString.toLowerCase();
originalString === convertedString // true// can't call with null / undefined
try{
console.log(null.toLowerCase());
}
catch(error){
console.log(error);
}
// TypeError: Cannot read property 'toLowerCase' of nullconsole.log("- - -");try{
console.log(undefined.toLowerCase());
}
catch(error){
console.log(error);
}
// TypeError: Cannot read property 'toLowerCase' of undefined

This is one of those methods that are as simple as they seem to be. Feed it a string value with capital letters and they will be replaced by their lowercase versions. Just like in case 1 and 2.

If there is no uppercase letter in the original string, the returned string is identical. You can see that in the next case where I have created a string with characters that are either lowercase or they do not have lowercase/uppercase versions. The resulting string is identical to the original one.

The last two cases cover TypeError that is thrown when we try to call the method with the “null” or with “undefined”. Don’t do that in real life — check if your string value exists. Or at least enclose it in a try/catch block.

Okay, that is as far as we can go with such a straightforward method like toLowerCase(). Thank you for your time and your attention. I will see you tomorrow with the next method.

--

--

--

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Recommended from Medium

Intro to fetch()

REDIS cache implementation for SpringBoot application

Service Workers in JavaScript — simple demo app

TEN Stack: Typescript-Express-Node template

🔸You can use whenever, just need access of the Internet and device.

Map, Set, WeakMap and WeakSet in Javascript

How to Reduce Your Vue.JS Bundle Size With Webpack

Dive into Reactive Forms

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jakub Korch

Jakub Korch

Web enthusiast, programmer, husband and a father. Wannabe entrepreneur. You name it.

More from Medium

Introduction to JavaScript

Difference Between find() and filter() methods in JavaScript

Notification with Audio in JavaScript

JavaScript: How to fix ng.ps1