A Common Problem
Then once were comfortable we will return to our scenario of the lowercase sentence.
Let’s take a string
Well let’s think we want to just uppercase the “e” in elephant and return the rest of the string onwards
JS already comes with two functions that help us let’s get into the code
A Shorter Way
If we don’t care about supporting older version of IE we can use s.toUpperCase() instead. To get the first letter
Also since were just using boolean true/false logic in capitalize we can leverage the ternary operator
We got the same result with shorter and more concise code. Without any major hits to readability.
Now that you’re comfortable with capitalizing the first letter of a single word. Are you ready to tackle whole sentences in our Capitalize First Word of Sentence in JS article coming soon