1
00:00:01,280 --> 00:00:05,600
Let's talk about another property which is called length.

2
00:00:05,840 --> 00:00:07,460
So let's comment out.

3
00:00:07,460 --> 00:00:11,390
This one's to avoid a lot of console.log.

4
00:00:11,720 --> 00:00:19,220
So let's have a nice comment here and call it as string length.

5
00:00:20,510 --> 00:00:20,960
Perfect.

6
00:00:20,960 --> 00:00:22,020
So what is it?

7
00:00:22,040 --> 00:00:28,070
Well, the length property retains the number of characters in a string, and the length property of

8
00:00:28,070 --> 00:00:30,830
an empty string is always zero.

9
00:00:31,160 --> 00:00:33,920
So what does it mean, actually?

10
00:00:33,920 --> 00:00:35,810
And what are some of the use cases here?

11
00:00:35,900 --> 00:00:44,300
So let's say that we have an application and we want users to register, but upon registration we want

12
00:00:44,300 --> 00:00:50,580
a user to enter, for example, user name, let's say ten characters or five characters long.

13
00:00:50,600 --> 00:00:56,920
In that way we are going to use the land property to check how many characters are present in a certain

14
00:00:57,080 --> 00:00:57,710
string.

15
00:00:57,890 --> 00:00:59,100
So let's see.

16
00:00:59,120 --> 00:01:07,220
Let's declare a variable const and let's call this one as last name is equal to.

17
00:01:08,080 --> 00:01:09,400
John Yeah.

18
00:01:09,400 --> 00:01:14,110
So how can I know or how many characters present in this particular string?

19
00:01:14,110 --> 00:01:15,550
And for this one is easy.

20
00:01:15,550 --> 00:01:18,660
You can count one, two, three, four.

21
00:01:18,670 --> 00:01:21,070
So let's allow JavaScript to count for us.

22
00:01:21,070 --> 00:01:28,870
So let's declare variable call results is equal to last name.

23
00:01:28,870 --> 00:01:31,920
And then on that we have the proper record length.

24
00:01:31,930 --> 00:01:35,830
This is not a method, but instead it's a property.

25
00:01:35,830 --> 00:01:41,560
So let's console.log the results and see the value we have.

26
00:01:41,590 --> 00:01:44,020
Indeed we have four.

27
00:01:44,500 --> 00:01:48,400
So let me show you one trick about this length property.

28
00:01:48,400 --> 00:01:51,370
It takes whitespace into consideration.

29
00:01:51,520 --> 00:01:55,120
So let's say that I have some spacing around this name.

30
00:01:55,540 --> 00:02:03,580
So if I save it now and see that I have five because it has counted the whitespace as well, if I have

31
00:02:03,580 --> 00:02:08,139
a lot of spacing to that, we see that it has increased to 12.

32
00:02:08,199 --> 00:02:16,990
So some sometimes if you are taking some data from users, sometimes users mistakenly provide some whitespace.

33
00:02:17,410 --> 00:02:24,040
So let's say that in your application you want to have, let's see, at least five characters, okay.

34
00:02:24,040 --> 00:02:31,210
Long, but the user indeed entered four characters but always said, oh, I entered five characters.

35
00:02:31,210 --> 00:02:38,530
But application says that have entered 12 characters not knowing that the user didn't count the whitespace

36
00:02:38,530 --> 00:02:39,700
into consideration.

37
00:02:39,700 --> 00:02:46,960
So as a developer, how can you solve it so we can solve it using another method called train, we get

38
00:02:46,960 --> 00:02:47,950
back into that.

39
00:02:48,070 --> 00:02:56,950
So the takeaway here is that we use length to know how many characters are present in a string and it

40
00:02:56,950 --> 00:03:00,070
takes whitespace in into consideration.

41
00:03:00,070 --> 00:03:00,340
All right.

42
00:03:00,340 --> 00:03:03,640
So in this video, let's have our first coding challenge.

