toUpperCase() method. Here's how you can achieve this:
1 2 3
const string = "hello world"; const uppercaseString = string.toUpperCase();
In this example,
string.toUpperCase() converts the
string to uppercase and assigns the result to the
uppercaseString variable. The resulting value will be
toUpperCase() method converts all the characters in the string to their uppercase equivalents according to the Unicode standard. It does not modify the original string but returns a new string with the uppercase characters.
If you want to convert only specific parts of a string to uppercase, you can use additional methods like
slice() or regular expressions. For example:
1 2 3
const string = "hello world"; const uppercaseFirstLetter = string.toUpperCase() + string.slice(1);
string.toUpperCase() converts the first character of the string to uppercase, and
string.slice(1) extracts the remaining characters. By concatenating the two parts, you get the result with the first letter capitalized:
Keep in mind that the
toUpperCase() method is based on the Unicode standard, so the behavior may vary for characters from different languages or scripts.