Make first letter of a string uppercase in JavaScript?

JavascriptWeb DevelopmentObject Oriented Programming

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
raja
Published on 12-Sep-2020 11:47:28
Advertisements