String toUpperCase() Method with Example in JavaScript

JavaScript String toUpperCase() Method: Here, we are going to learn about the toUpperCase() method of the string in JavaScript with Example.
Submitted by IncludeHelp, on February 05, 2019

String toUpperCase() Method

toUpperCase() Method is a string method in JavaScript, it is used to converts all alphabets in uppercase and returns the new string with uppercase alphabets.

Syntax:

    new_string = str.toUpperCase();

Here,

  • str is the main string to be converted.
  • new_string is the returned new string with all alphabets in uppercase.

Examples:

    Input: "Hello World!"
    Output: "HELLO WORLD!"
    Input: "Hello123@"
    Output: "HELLO123@"

Code:

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
<script>		
	var main_str = "Hello World!";
	var new_str = main_str.toUpperCase();
	document.write("main_str =  " + main_str + "<br>");
	document.write("new_str =  " + new_str + "<br>");

	main_str = "Hello123@";
	new_str = main_str.toUpperCase();
	document.write("main_str =  " + main_str + "<br>");
	document.write("new_str =  " + new_str + "<br>");	
</script>
</body>
</html>

Output

main_str = Hello World!
new_str = HELLO WORLD!
main_str = Hello123@
new_str = HELLO123@

JavaScript String Object Methods »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.