JavaScript String toLowerCase and toUpperCase

In this short video, you will learn how to change the JavaScript String to lower and upper cases using methods available on String Constructor. We will use .toLowerCase() and .toUpperCase() methods.

Code

let text = `YOU might not make it to the TOP, but if you are doing what you love,
there is much more happiness there than being RICH or FAMOUS`;
let upper = text.toUpperCase()
console.log(upper)
let lower = text.toLowerCase()
console.log(lower)

Full Transcript

0:00 Hey, it's Harit Himanshu from bonsaiilabs. Welcome to the series on JavaScript. Today. In this short video, you will learn about how to change the casing of a text. Let's say you are reading a book online and you found a great quote that you thought your friend might like it. You decided to send this quote over an email to motivate them, but then, you realize that the quote is filled with lowercase and uppercase as mixed, but you don't want to stress on a particular highlights of the quote. So how do you make everything in small case? Well, as a JavaScript programmer, it's pretty easy to do. The first thing you have to do is that you assign the quote to a text variable. Next, you call the toLowerCase method available on the string. This returns a new string which contains the quote all in the lower case.

0:40 We can confirm this by printing the new value returned on the console and confirming the output. But you love this quote so much that you decided to tweet about it, but the lowercase version does not express the happiness and the energy you get when you read it. So decided to make everything in the capital case before you tweet. Now looking at the previous example, it is pretty easily achievable in JavaScript. This time, again, you add a quote to the text variable, then you call the toUpperCase method available on the string. This returns a new string back without modifying the existing quote text. We can confirm this by printing the new value on the console and confirming the output. Great. So as you see, depending upon how you want to express your content, the string constructor provides the utilities for us as developers to use, and that's it. I hope you learned something new today. If you liked the video, please hit the subscribe button on our channel to receive more engaging content about JavaScript every single week. Until then, keep learning new skills and apply them regularly to become an expert programmer. See you next time.