From 649d1c3ae0ba7ae263a3062d977b99d811a016fc Mon Sep 17 00:00:00 2001 From: Ivan Babak Date: Mon, 11 Dec 2017 18:29:37 -0800 Subject: [PATCH] Capitalize first letter: safe against empty string `""[0]` -> `undefined` `"".slice(0, 1)` -> `""` --- snippets/capitalize-first-letter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/capitalize-first-letter.md b/snippets/capitalize-first-letter.md index 56e42eab5..84447ee21 100644 --- a/snippets/capitalize-first-letter.md +++ b/snippets/capitalize-first-letter.md @@ -3,5 +3,5 @@ Use `toUpperCase()` to capitalize first letter, `slice(1)` to get the rest of the string. ```js -var capitalize = str => str[0].toUpperCase() + str.slice(1); +var capitalize = str => str.slice(0, 1).toUpperCase() + str.slice(1); ```