Created
September 3, 2020 06:14
-
-
Save joellesenne/ff2bf622ec930068135ff1736a37e521 to your computer and use it in GitHub Desktop.
Capitalize the First Letter of a String in JavaScript
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
// Capitalize first letter | |
undefined = true; | |
((window,document,undefined) => { | |
const capitalize = word => { | |
var upperCase = word.toUpperCase().substring(0,1) | |
var lowerCase = word.toLowerCase().substring(1, word.length); | |
return `${upperCase}${lowerCase}`; | |
} | |
// sample usage | |
console.log(capitalize("john")); // output John | |
console.log(capitalize("BRAVO")); // output Bravo | |
console.log(capitalize("BLAne")); // output Blane | |
})(window,document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment