Let's talk about another property which is called length.
So let's comment out.
This one's to avoid a lot of console.log.
So let's have a nice comment here and call it as string length.
Perfect.
So what is it?
Well, the length property retains the number of characters in a string, and the length property of
an empty string is always zero.
So what does it mean, actually?
And what are some of the use cases here?
So let's say that we have an application and we want users to register, but upon registration we want
a user to enter, for example, user name, let's say ten characters or five characters long.
In that way we are going to use the land property to check how many characters are present in a certain
string.
So let's see.
Let's declare a variable const and let's call this one as last name is equal to.
John Yeah.
So how can I know or how many characters present in this particular string?
And for this one is easy.
You can count one, two, three, four.
So let's allow JavaScript to count for us.
So let's declare variable call results is equal to last name.
And then on that we have the proper record length.
This is not a method, but instead it's a property.
So let's console.log the results and see the value we have.
Indeed we have four.
So let me show you one trick about this length property.
It takes whitespace into consideration.
So let's say that I have some spacing around this name.
So if I save it now and see that I have five because it has counted the whitespace as well, if I have
a lot of spacing to that, we see that it has increased to 12.
So some sometimes if you are taking some data from users, sometimes users mistakenly provide some whitespace.
So let's say that in your application you want to have, let's see, at least five characters, okay.
Long, but the user indeed entered four characters but always said, oh, I entered five characters.
But application says that have entered 12 characters not knowing that the user didn't count the whitespace
into consideration.
So as a developer, how can you solve it so we can solve it using another method called train, we get
back into that.
So the takeaway here is that we use length to know how many characters are present in a string and it
takes whitespace in into consideration.
All right.
So in this video, let's have our first coding challenge.