Created
August 21, 2021 16:12
-
-
Save matthewoestreich/e4014fd44ec68e9c4046f902b8680837 to your computer and use it in GitHub Desktop.
caps first letter in str
This file contains hidden or 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
function capsFirstLetter(str) { | |
if (typeof str !== "string") { | |
throw new Error("param `str` must be a string!"); | |
} | |
const firstLetterCaps = str[0].toUpperCase(); | |
const restOfString = str.slice(1); | |
return firstLetterCaps + restOfString; | |
} | |
const myStr = "something"; | |
const results = capsFirstLetter(myStr) | |
console.log(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment