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