Easy

Caps

Prompt

Write a function that takes a single string argument and returns the string in all uppercase letters.

You probably won't get asked this exact question in an interview. But it shows up as part of solving many other questions, so it's worth knowing. If it does come up, it'll likely be in a multiple-choice format rather than coding from scratch. Think of it as adding a small tool to your toolkit.

Playground

Hint

JavaScript strings have a built-in method that converts all characters to uppercase. It returns a new string without modifying the original.

Solution

Explanation

One line. toUpperCase() is a built-in string method that returns a new string with all alphabetic characters converted to uppercase. Numbers, symbols, and spaces are left unchanged.

'hello'.toUpperCase(); // "HELLO"
'abc123'.toUpperCase(); // "ABC123"

An important thing to know: toUpperCase() doesn't modify the original string. Strings in JavaScript are immutable. It always returns a new string. This is true for all string methods like toLowerCase(), trim(), slice(), etc.