How to uppercase (capitalize) the first letter (character) of a string in TypeScript

2 Answers

0 votes
function UppercaseFirstCharacter(s: string) {
    return s.charAt(0).toUpperCase() + s.slice(1);
}
  
let s: string = 'typescript programming language';
   
s = UppercaseFirstCharacter(s);
   
console.log(s);
   
   
  
   
/*
   
run:
   
"Typescript programming language" 
   
*/

 

 

 



answered Mar 18, 2024 by avibootz
0 votes
function UppercaseFirstCharacter(s: string) {
    return s.charAt(0).toUpperCase() + s.substring(1)
}
  
let s: string = 'typescript programming language';
   
s = UppercaseFirstCharacter(s);
   
console.log(s);
   
   
  
   
/*
   
run:
   
"Typescript programming language" 
   
*/

 

 



answered Mar 18, 2024 by avibootz
...