Files
30-seconds-of-code/snippets/capitalize-first-letter.md
Ivan Babak f53bbbe128 Capitalize first letter: safe against empty string
`""[0]` -> `undefined`
`"".slice(0, 1)` -> `""`
2017-12-11 18:29:37 -08:00

200 B

Capitalize first letter

Use toUpperCase() to capitalize first letter, slice(1) to get the rest of the string.

var capitalize = str => str.slice(0, 1).toUpperCase() + str.slice(1);