Make First Letter of a String Uppercase in JavaScript



To make first letter of a string uppercase, use toUpperCase() in JavaScript. With that, we will use charAt(0) since we need to only capitalize the 1st letter.

Example

function replaceWithTheCapitalLetter(values){
   return values.charAt(0).toUpperCase() + values.slice(1);
}
var word="javascript"
console.log(replaceWithTheCapitalLetter(word));

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo167.js.

Output

This will produce the following output −

PS C:\Users\Amit\javascript-code> node demo167.js
Javascript
Updated on: 2020-09-12T08:17:51+05:30

388 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements