Last active
September 2, 2019 06:32
-
-
Save LeanSeverino1022/999dc5a9206eea8487129e1f361da21c to your computer and use it in GitHub Desktop.
capitalize first letter #strings #vanillajs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const capitalizeFirstLetter = (s) => { | |
if (typeof s !== 'string') return '' | |
return s.charAt(0).toUpperCase() + s.slice(1) | |
} | |
capitalizeFirstLetter('puyih') //'Puyih' | |
capitalizeFirstLetter('p') //'P' | |
capitalizeFirstLetter(0) //'' | |
capitalizeFirstLetter({}) //'' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment