first letter capital in jquery 1

first letter capital in jquery

// Define function to capitalize the first letter of a string
function capitalizeFirstLetter(string){
  return string.charAt(0).toUpperCase() + string.slice(1);

// Calling function and display the result
var str1 = 'hi there!';
str1 = capitalizeFirstLetter(str1);
document.write(str1); // Print: Hi there!

Here is what the above code is Doing:
1. Define a function called capitalizeFirstLetter() that takes a string as an argument.
2. Inside the function, return the string with the first letter capitalized.
3. Call the function and pass it a string.
4. Assign the result of the function to a variable.
5. Display the result.

Similar Posts