JavaScript Code

How to make first letter of string an Uppercase using JavaScript?

Make first letter of string an Uppercase in JavaScript

In this tutorial, you are given a string. Make first letter of the string an uppercase using JavaScript.


To make the first character of a string an uppercase using JavaScript, get the first character using charAt() method, convert it to uppercase using toUpperCase() method, and append the substring from start=1 to the uppercase character.

myStr.charAt(0).toUpperCase() + myStr.slice(1)


1. Given a string value in str. Convert the first character to uppercase.

myStr = "hello world";
output = myStr.charAt(0).toUpperCase() + myStr.slice(1);