DEV Community

Deep Space
Deep Space

Posted on

JavaScript String length Property

Hey there!
In this post and video, I'm going to explain how to use JavaScript length property with strings to find/count the number of characters in a string

When you use the length property with JavaScript strings it counts the number of characters you have in that string and returns a/an positive/integer number. That includes empty string, empty space.

Let's create 2 variables:

let firstName = 'Ada';
let myData = firstName.length; // returns 3
console.log(myData);
Enter fullscreen mode Exit fullscreen mode

The way it's used is after or at the end of a variable with a .length like so firstName.length

If you check the typeof both variables the firstName is a string.
And myData is a number.

console.log(typeof firstName); // string
console.log(typeof myData);    // number
Enter fullscreen mode Exit fullscreen mode

If you are a visual person here's a video tutorial with code editor and whiteboard example.

Thanks for reading this.

Discussion (0)