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

javascriptstring.toUpperCase();

Example

Let's convert all letters to uppercase:

javascriptlet str = 'abcde';
console.log(str.toUpperCase());

The code execution result:

javascript'ABCDE'

Example

Also using the slice method you can convert individual letters to uppercase:

javascriptlet str = 'abcde';
let res = str.slice(0, 1).toUpperCase() + str.slice(1);

console.log(res);

The code execution result:

javascript'Abcde'

See also

  • the toLowerCase method
    that converts a string to lowercase
  • the charAt method
    that returns a character in a string