1With performance metrics...
2
3// 10,889,187 operations/sec
4function capitalizeFirstLetter(string) {
5 return string[0].toUpperCase() + string.slice(1);
6}
7
8// 10,875,535 operations/sec
9function capitalizeFirstLetter(string) {
10 return string.charAt(0).toUpperCase() + string.slice(1);
11}
12
13// 4,632,536 operations/sec
14function capitalizeFirstLetter(string) {
15 return string.replace(/^./, string[0].toUpperCase());
16}
17
18// 1,977,828 operations/sec
19String.prototype.capitalizeFirstLetter = function() {
20 return this.charAt(0).toUpperCase() + this.slice(1);
21}
22