What is the length property in JavaScript?
The length property returns the number of characters in a string. The functionality of length is shown in the illustration below:
Syntax
The length property is declared as follows:
Parameters
The length property does not take any parameters.
Return value
The length property returns the length of the string as an integer number. If the string is empty, zero is returned.
Examples
The following code shows the use of the length property in JavaScript:
//Example 1str = "Hello";console.log(str.length);//Example 2str2 = "";console.log(str2.length);
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved