javascript tolowercase

JavaScript tolowercase is a string function that is used to convert a string or text line to lowercase letters. JavaScript also has another function with tolowercase function called touppercase.

Related: 5 Javascript Replace Method you must know!

We have some easy examples of JavaScript tolowercase and touppercase available to teach you in a better way, after seeing which you will know how to use tolowercase in JavaScript.

Syntax

In the syntax given below, you can see that we have taken a variable named string which is used with the toLowerCase () function.

string.toLowerCase()

JavaScript tolowercase

In the below example, we have a variable named mystring, inside which we put our string. And we have shown the result with the document.write function.

<script>
	var mystring = "This IS MY StrING";
	var result = mystring.toLowerCase();
	document.write(result);
</script>

Example 2

<script>
	var mystring = "THIS IS MY SECOND STRING";
	var result = mystring.toLowerCase();
	document.write(result);
</script>

JavaScript Onclick Tolowercase

If you want to convert your string to lowercase letters using Onclick, then for that you will have to create a function. In the following example, you can learn how JavaScript onclick works.

<button onclick="LowerFunction()">Convert To Lower</button>

<b id="Lower"></b> 

<script>
	function LowerFunction() {
		var mystring = "This IS MY StrING";
		var result = mystring.toLowerCase();
		document.getElementById("Lower").innerHTML = result;
	}
</script>

JavaScript Uppercase

If you want to convert your string to uppercase letters, then you have to use the JavaScript uppercase function. Let’s know how to use touppercase in JavaScript.

<script>
	var mystring = "this is my upper case string";
	var result = mystring.toUpperCase();
	document.write(result);
</script>

Example 2 Onclick

<button onclick="UpperFunction()">Convert To Upper</button>
<b id="Upper"></b>
<script>
	function UpperFunction() {
		var mystring = "this is my upper case string";
		var result = mystring.toUpperCase();
		document.getElementById("Upper").innerHTML = result;
	}
</script>

JavaScript capitalize first letter

If you want to convert the first letter of your string to UpperCase, then for that you have to use charAt() function with toUpperCase function.

Related: 7 easiest examples of javascript trim

The charAt() function is used to return the position of any character. In the example shown below, we have picked up the letter at position 0 with the charAt() function and converted it to Uppercase.

<script>
	var mystring = "this is my string";
	var result = mystring.charAt(0).toUpperCase() + mystring.slice(1)
	document.write(result);
</script>

JavaScript lowercase first letter

If you want to convert the first letter of your string to lowercase, then for that you can be using the same method mentioned above.

<script>
	var mystring = "THIS IS MY STRING";
	var result = mystring.charAt(0).toLowerCase() + mystring.slice(1)
	document.write(result);
</script>

Related: 10 awesome examples of javascript else if condition

Related: 12 easiest examples of javascript onclick