Convert string into uppercase and lowercase in javascript

JavaScript has in-built functions for strings like slice(), substring() and replace() methods. Here, we will use in-built methods like toUpperCase() and toLowerCase().

In this tutorial, we will convert string into uppercase and lowercase with JavaScript.

Convert String Into Uppercase In JavaScript

String conversion to uppercase are frequently used in web development. Here, we store value of string into variable and then bind toUpperCase() method to that string variable. It will automatically convert string into uppercase.

Here, the toUpperCase() method will convert given variable value and return new value as upper string. Following is syntax of toUpperCase() method.


str.toUpperCase();

Let's take example to understand it.


var str = "this is simple string.";
strUpper = str.toUpperCase();

console.log(strUpper);

//Output:- THIS IS SIMPLE STRING.

Convert String Into lowercase In JavaScript

The toLowerCase() function works same as upper case function. We just have to bind this method with string variable and it will convert string value into lowercase.

Here, the toLowerCase() method will convert given variable value and return new value as lowercase string. Following is syntax of toLowerCase() method.


str.toLowerCase();

Let's take example to understand it.


var str = "THIS IS SIMPLE STRING.";
strLower = str.toLowerCase();

console.log(strLower);

//Output:- this is simple string.

Conclusion

In this article, we demonstrated how to convert string value into lowercase or uppercase easily using the toUpperCase() and toLowerCase() methods.


Share your thoughts

Ask anything about this examples