Search This Blog

2026/08/11

Javascript:Capitalize first and last character in sentence

 



Capitalize first and last character in sentence.

Code:

let sentence = "hello john how do you do"

function firstCharCapital(sentence){
  return sentence.at(0).toUpperCase() + sentence.slice(1)
}

function lastCharCapital(sentence){
   return  sentence.slice(0,sentence.length -1 ) +  sentence.at(sentence.length -1).toUpperCase()
}

let firstCharCapitalized = firstCharCapital(sentence)
console.log(firstCharCapitalized)


let lastCharCapitalized = lastCharCapital(sentence)
console.log(lastCharCapitalized)

Output:
Hello john how do you do
hello john how do you dO

Explanation:I have written two functions to get desired result we can call them one
on other like firstCharCapital(lastCharCapital(sentence))

Javascript:bigint datatype



How to use large number in javascript?

Code:

let num1 =123456777867;
let num2 = 5324152355467563;
console.log(num1 *num2); //6.573026946790237e+26

let num3 =123456777867n;
let num4 = 5324152355467563n;
console.log(num3 *num4); //657302694679023748214828121n

output:
6.573026946790237e+26
657302694679023748214828121n

Explanation:
   when number are large there result is aproximated by default
   you can use n at end to declare it as bigint,bigint can store

   large number,if n is at end of number then it is bigint datatype.