toUpperCase() in JavaScript – How to Convert String to Uppercase
Whenever you use toUpperCase() on a string, the method does the following:
- It converts its calling string to uppercase.
- It returns the new version of the calling string—without changing the original string.
Use JavaScript’s toUpperCase() method to convert your string to uppercase.
Syntax of the toUpperCase()
Method
Here is toUpperCase()
’s syntax:
callingString.toUpperCase();
The snippet above shows that toUpperCase()
does not accept any argument.
Example 1: Convert CodeSweetly
to Uppercase
"CodeSweetly".toUpperCase();
// The invocation above will return: "CODESWEETLY"
Example 2: Convert a JavaScript String to Uppercase
"friday, my friend, was born on friday".toUpperCase();
// The invocation above will return: "FRIDAY, MY FRIEND, WAS BORN ON FRIDAY"