JavaScript | string.length
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.
Code #1:
<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> |
chevron_right
filter_none
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> |
chevron_right
filter_none
Output:
10 13 2
Recommended Posts:
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Variables in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


