How to use JavaScript String length

String length

On this page

String length

Program to use JavaScript String .length

let a = "Hello World in JavaScript";
    let b = a.length;
    console.log("String length =",b);
    

Output

String length = 25
    

Steps Description

  • Declare two variable a and b
  • Initialize two variable with value of string a = “Hello World in JavaScript” and b
  • String .length Calculates the length of a string by counting its characters and output it as a number.
  • The value of b variable is displayed with the help of console.log inbuilt function