• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
November 05, 2022 |1.2K Views

JavaScript Program to Convert the First Letter of a String into UpperCase

  Share   Like
Description
Discussion

In this video, we write a JavaScript program to convert the first letter of a string into uppercase.

Program to convert first letter of a string into Uppercase (3 Approaches)

1. toUpperCase()
2. slice()
3. replace()

Example:
Input string : geeksforgeeks
Output string : Geeksforgeeks

Input string: javascript
Output string: Javascript

1) toUpperCase():In this method we use toUppercase(). Basically, this function applies to a string and changes all letters to uppercase.
Syntax: string.toUpperCase()
 

2) slice():
This function applies to a string and slices it according to the passed parameter.
Syntax: string.slice(start, end
 

3) replace():
This is a built-in function in JavaScript that is used to replace a slice of a string with another string or a regular expression. The original string will not be affected.
Syntax: str.replace(A, B)

JavaScript program to convert the first letter of a string into uppercase
https://www.geeksforgeeks.org/how-to-make-first-letter-of-a-string-uppercase-in-javascript/