JavaScript: Uppercase first letter in a string. June 30, 2010. In PHP there is a very handy function called ucfirst which. Returns a string with the first character of str capitalized, if that character is alphabetic. Needed that in JavaScript, but discovered there was no such thing. Luckily I quickly found a function over at StackOverflow that I adjusted slightly and added to the string class: