1
00:00:02,469 --> 00:00:04,490
Now there is one last

2
00:00:04,490 --> 00:00:08,260
characteristic about strings which I want to show to you,

3
00:00:08,260 --> 00:00:11,483
which is related to arrays actually.

4
00:00:12,500 --> 00:00:17,070
Let's say we have a certain username

5
00:00:18,850 --> 00:00:20,793
Max here in this case,

6
00:00:21,750 --> 00:00:25,930
and now we want to find out how long that name is.

7
00:00:25,930 --> 00:00:27,860
As a human we can count it,

8
00:00:27,860 --> 00:00:32,159
but we don't always want to count because it's error prone.

9
00:00:32,159 --> 00:00:35,900
And in our running application, in our running website,

10
00:00:35,900 --> 00:00:40,460
that variable value might actually not be hard coded into

11
00:00:40,460 --> 00:00:42,440
this code as it's currently.

12
00:00:42,440 --> 00:00:46,040
But instead we might be fetching this from some input field

13
00:00:46,040 --> 00:00:49,320
on the page, and that is actually something

14
00:00:49,320 --> 00:00:53,200
we will be doing in this demo I showed you earlier.

15
00:00:53,200 --> 00:00:57,263
Which we are going to build in the next course section,

16
00:00:58,220 --> 00:01:01,370
because in this demo we need to count

17
00:01:01,370 --> 00:01:04,030
the length of the user input,

18
00:01:04,030 --> 00:01:06,740
which of course changes with every keystroke

19
00:01:06,740 --> 00:01:09,660
and which we as a developer therefore don't know

20
00:01:09,660 --> 00:01:14,350
in advance, and in situations like this we need a way of

21
00:01:14,350 --> 00:01:18,900
finding out how long some text is.

22
00:01:18,900 --> 00:01:22,300
So it's not something we need here for this example,

23
00:01:22,300 --> 00:01:24,710
this hard coded string,

24
00:01:24,710 --> 00:01:28,110
which means a value we define as a developer,

25
00:01:28,110 --> 00:01:29,580
which never changes,

26
00:01:29,580 --> 00:01:33,660
which does not depend on some input of the website visitor.

27
00:01:33,660 --> 00:01:36,230
Here it is just hard coded, and therefore,

28
00:01:36,230 --> 00:01:38,240
we could count it manually,

29
00:01:38,240 --> 00:01:40,410
but let's assume we're getting this from

30
00:01:40,410 --> 00:01:44,090
some dynamic input, and we don't know the length in advance.

31
00:01:44,090 --> 00:01:47,470
In such cases, we might want to derive the length

32
00:01:47,470 --> 00:01:48,720
programmatically,

33
00:01:48,720 --> 00:01:53,230
and that is thankfully easy to do in Java script.

34
00:01:53,230 --> 00:01:57,010
We can just use the string that we want to count,

35
00:01:57,010 --> 00:01:58,910
or the variable that holds the string,

36
00:01:58,910 --> 00:02:00,330
which I have in this case

37
00:02:00,330 --> 00:02:05,053
and then use the dot notation to access dot length.

38
00:02:05,990 --> 00:02:10,500
And that's really important, and maybe also confusing.

39
00:02:10,500 --> 00:02:13,840
A string is not an object.

40
00:02:13,840 --> 00:02:17,960
And yet we can use the dot notation on a string

41
00:02:17,960 --> 00:02:21,140
to access various methods.

42
00:02:21,140 --> 00:02:24,530
Since we have this purple kind of blocks here,

43
00:02:24,530 --> 00:02:28,500
on that string, and we also have this length property,

44
00:02:28,500 --> 00:02:30,673
in addition to all these methods.

45
00:02:31,590 --> 00:02:35,140
Now this is simply something that's built into JavaScript.

46
00:02:35,140 --> 00:02:39,100
You could say that all the strings you are creating are

47
00:02:39,100 --> 00:02:43,530
automatically wrapped with an invisible object behind the

48
00:02:43,530 --> 00:02:45,520
scenes, by Java script,

49
00:02:45,520 --> 00:02:49,100
so that you have certain properties that you can access on

50
00:02:49,100 --> 00:02:50,400
your strings.

51
00:02:50,400 --> 00:02:55,270
So they kind of are converted into objects behind the scenes

52
00:02:55,270 --> 00:02:57,180
and we have this behavior

53
00:02:57,180 --> 00:03:01,303
so that we have certain functionalities or utilities

54
00:03:01,303 --> 00:03:04,550
that we can access on these strings.

55
00:03:04,550 --> 00:03:06,660
Like for example, dot length,

56
00:03:06,660 --> 00:03:08,950
to get the length of this string,

57
00:03:08,950 --> 00:03:12,003
the number of characters that make up this string.

58
00:03:13,220 --> 00:03:18,090
And if I saved this, then I get three here as a result,

59
00:03:18,090 --> 00:03:22,103
which of course is the length of this Max string.

60
00:03:23,640 --> 00:03:26,850
And as you can see, if I,

61
00:03:26,850 --> 00:03:31,820
again add a dot here and I get this suggestion popup,

62
00:03:31,820 --> 00:03:34,440
there is way more than just length.

63
00:03:34,440 --> 00:03:36,640
And you see we have a bunch of methods here,

64
00:03:36,640 --> 00:03:39,050
which we can access on our string,

65
00:03:39,050 --> 00:03:41,500
and that length property which we saw.

66
00:03:41,500 --> 00:03:44,440
And definitely feel free to play around with them.

67
00:03:44,440 --> 00:03:47,710
For example, there is the toUpperCase method,

68
00:03:47,710 --> 00:03:50,180
and since it's a method we need to execute it

69
00:03:50,180 --> 00:03:52,770
by adding these parentheses here.

70
00:03:52,770 --> 00:03:56,550
And if I call that, then I get this string

71
00:03:56,550 --> 00:03:59,513
converted to all uppercase characters.

72
00:04:00,360 --> 00:04:03,220
So these are utility functionalities,

73
00:04:03,220 --> 00:04:06,323
which can come in handy from time to time.

