JavaScript: String toUpperCase() method
This JavaScript tutorial explains how to use the string method called toUpperCase() with syntax and examples.
Description
In JavaScript, toUpperCase() is a string method that is used to convert a string to uppercase. Because the toUpperCase() method is a method of the String object, it must be invoked through a particular instance of the String class.
Syntax
In JavaScript, the syntax for the toUpperCase() method is:
string.toUpperCase();
Parameters or Arguments
There are no parameters or arguments for the toUpperCase() method.
Returns
The toUpperCase() method returns a string converted to uppercase.
Note
- The toUpperCase() method does not change the value of the original string.
Example
Let's take a look at an example of how to use the toUpperCase() method in JavaScript.
For example:
var totn_string = 'TechOnTheNet';
console.log(totn_string.toUpperCase());
In this example, we have declared a variable called totn_string that is assigned the string value of 'TechOnTheNet'. We have then invoked the toUpperCase() method of the totn_string variable to convert the string to uppercase.
We have written the output of the toUpperCase() method to the web browser console log, for demonstration purposes, to show what the toUpperCase() method returns.
The following will be output to the web browser console log:
TECHONTHENET
In this example, the toUpperCase() method converted the string 'TechOnTheNet' to uppercase and returned a string value of 'TECHONTHENET'.
Advertisements