The toUpperCase() method of the String class in JavaScript returns the calling string value converted to uppercase.
The syntax of String.toUpperCase() method is:
toUpperCase()
This toUpperCase() method of String returns the calling string value converted to uppercase.
String.toUpperCase() returns value of type String
.
In JavaScript, the toUpperCase()
method converts a string to uppercase letters.
For example,
str
with the value 'hello world'
.toUpperCase()
method to convert the string to uppercase.upperStr
.upperStr
to the console using the console.log()
method.const str = 'hello world';
const upperStr = str.toUpperCase();
console.log(upperStr);
HELLO WORLD
In JavaScript, the toUpperCase()
method can be used to convert a string with mixed case letters to all uppercase letters.
For example,
str
with the value 'JavaScript'
.toUpperCase()
method to convert the string to uppercase.upperStr
.upperStr
to the console using the console.log()
method.const str = 'JavaScript';
const upperStr = str.toUpperCase();
console.log(upperStr);
JAVASCRIPT
In JavaScript, the toUpperCase()
method only affects alphabetic characters and leaves numbers and symbols unchanged.
For example,
str
with the value 'Hello 123!'
.toUpperCase()
method to convert the alphabetic characters to uppercase.upperStr
.upperStr
to the console using the console.log()
method.const str = 'Hello 123!';
const upperStr = str.toUpperCase();
console.log(upperStr);
HELLO 123!
In this JavaScript tutorial, we learned about toUpperCase() method of String: the syntax and few working examples with output and detailed explanation for each example.