JavaScript Code

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


Problem Statement

given a string, make first letter of the string an uppercase using JavaScript

Solution

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)

Program

1. given string is str. convert the first character to uppercase

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