toUpperCase method
The toUpperCase method converts
a string to uppercase (makes capital
letters from small). This returns a
new string and does not change the
original string.
Syntax
string.toUpperCase();
Example
Let's convert all letters to uppercase:
let str = 'abcde';
console.log(str.toUpperCase());
The code execution result:
'ABCDE'
Example
Also using the
slice
method you can convert individual letters
to uppercase:
let str = 'abcde';
let res = str.slice(0, 1).toUpperCase() + str.slice(1);
console.log(res);
The code execution result:
'Abcde'
See also
-
the
toLowerCasemethod
that converts a string to lowercase -
the
charAtmethod
that returns a character in a string