Problem

Retool’s app-building framework and 100+ pre-built UI components can help you build any interface 10x faster (not exaggerating).

function capitalize(string) {
  string[0].toUpperCase()
  return string
}
Solution

When we call toUpperCase, we’re assuming that we’re modifying the string that was passed into the function. However, since strings are primitive values, that means they’re immutable and can’t be modified once they’ve been created. Instead of trying to modify the string directly, we need to return a new string after capitalizing the first character.

const capitalize = ([firstLetter, ...restOfWord]) => {
  return firstLetter.toUpperCase() + restOfWord.join('')
}

For more information, visit How to capitalize the first letter of a string in JavaScript