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 1
str = "Hello";
console.log(str.length);
//Example 2
str2 = "";
console.log(str2.length);
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved