JavaScript String length property

The length property in JavaScript is used to get the length of a string. This property is a read-only property of strings in JavaScript, and returns the number of characters in the string.

Here is an example of how the length property works:

const string1 = 'Hello, world!';

const result = string1.length;

// the result will be: 13

In the code example above, we first declare a string called string1 that contains the text Hello, world!. We then use the length property to get the length of the string1 string. The length property is a read-only property of strings in JavaScript, and can be accessed by using the . dot notation on a string. In this case, we access the length property on the string1 string.

As a result of accessing the length property, the result variable will be set to 13, which is the number of characters in the string1 string.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: