Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript | string.length

  • Last Updated : 02 Jul, 2018

The string.length is a property in JavaScript which is used to find the length of a given string.
Syntax:

string.length

Parameter: It does not accept any parameter.
Return Values: It returns the length of the given string.

JavaScript code to show the working of string.length property:

Code #1:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!




<script>
  
    // Taking some strings
    var x = 'geeksforgeeks';
    var y = 'gfg';
    var z = '';
  
    // Returning the length of the string.
    document.write(x.length + "<br>");
    document.write(y.length + "<br>");
    document.write(z.length);
  
</script>

Output:

13
3
0

Code #2:




<script>
  
    // Taking some strings.
    var x = '2341312134';
    var y = '@#$%^&**((*&^';
  
    // Variable z contains two spaces
    var z = '  ';
  
    // Returning the length of the string.
    document.write(x.length + "<br>");
    document.write(y.length + "<br>");
    document.write(z.length);
  
</script>

Output:

10
13
2



My Personal Notes arrow_drop_up
Recommended Articles
Page :