Skip to content

Instantly share code, notes, and snippets.

@ashishlahoti
Created June 20, 2020 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashishlahoti/6082f3becae9b59ec00f499a04830d62 to your computer and use it in GitHub Desktop.
Save ashishlahoti/6082f3becae9b59ec00f499a04830d62 to your computer and use it in GitHub Desktop.
How to Capitalize First Letter of String in JavaScript
// es5 way
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
// es6 way using destructuring
const capitalize = ([first,...rest]) => first.toUpperCase() + rest.join('');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment