Skip to content

Instantly share code, notes, and snippets.

@LeanSeverino1022
Last active September 2, 2019 06:32
Show Gist options
  • Save LeanSeverino1022/999dc5a9206eea8487129e1f361da21c to your computer and use it in GitHub Desktop.
Save LeanSeverino1022/999dc5a9206eea8487129e1f361da21c to your computer and use it in GitHub Desktop.
capitalize first letter #strings #vanillajs
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