DEV Community

Deep Space
Deep Space

Posted on

1 1

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.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more