JavaScript Capitalize
Capitalize is not a built-in JavaScript method. It is composed from two: charAt(0).toUpperCase() uppercases the first letter, then slice(1) appends the rest. A perfect first example of chaining functions.
Syntax
str.charAt(0).toUpperCase() + str.slice(1) Examples
| Input | Arguments | Output |
|---|---|---|
| "hello world" | — | "Hello world" |
| "éric" | — | "Éric" |
When to use it
- Format names, titles and labels for display.
Gotchas
- Only capitalises the first character, not every word. Chain split(" ") + map to title-case a full sentence.
Try it live
Type your input and see Capitalize transform it instantly.
Want to go further? Chain Capitalize with other functions, pipe one output into the next and watch your data transform in the visual Playground.