How to Find String Length in JavaScript using Function

JavaScript String Length Function

Learn the javascript string length function with example codes. The length function works only to find the length of the string only. If we try to find the length of an integer or float, then it returns “undefined”. This function calculates the space in the string and returns the length value.

Example code:

var str1= "Hello world";
var str2 = 17.3;


 javascript string length function

  1. Here, we have created a variable called str1 and str2. We assigned the string value to str1 and the integer value to str2.
  2. We know that the length function allows only string variables. If we pass an integer then it returns “undefined”.
  3. See, the above output the str1 length is 11 and the str2 length is undefined.

Leave a Reply