1
00:00:00,480 --> 00:00:05,700
This section is all about JavaScript strings.

2
00:00:05,730 --> 00:00:14,130
We will dive in more to talk about how to create a string and some of the commonly used methods when

3
00:00:14,130 --> 00:00:15,390
it comes to string.

4
00:00:15,390 --> 00:00:21,390
And also we will learn how to compare string that is string comparison.

5
00:00:21,480 --> 00:00:27,780
And above all, there are going to be a lot of coding challenges at the end of each concept.

6
00:00:27,780 --> 00:00:29,700
So let's get started.

7
00:00:29,730 --> 00:00:32,910
The first question is what is a string?

8
00:00:32,910 --> 00:00:40,410
Where in JavaScript strings are lines of text that are used to store and represent data?

9
00:00:40,950 --> 00:00:50,640
Strings can be anything from a single character to an entire novel or story, so any sequence of characters

10
00:00:50,640 --> 00:00:58,500
can be stored as a string, and string must always be placed within either a single or double quotation

11
00:00:58,500 --> 00:00:59,100
mark.

12
00:00:59,310 --> 00:01:05,640
Well, so strings are everywhere in programming, so we have been using a lot of them.

13
00:01:05,640 --> 00:01:08,910
So a string is also a type of.

14
00:01:09,640 --> 00:01:11,530
Did I type in JavaScript?

15
00:01:11,560 --> 00:01:18,550
So in this video, let's go ahead and learn how to create a string back to visualize clear code.

16
00:01:18,730 --> 00:01:26,530
I have already created a folder and I have named mine folder as strings.

17
00:01:28,100 --> 00:01:35,020
And inside I have two files index HTML and script dot js.

18
00:01:35,030 --> 00:01:44,150
So for the index there are few lines of HTML over here and I just link up my JavaScript file.

19
00:01:44,390 --> 00:01:49,490
There's nothing new until this point, so let's get started with JavaScript.

20
00:01:49,490 --> 00:01:56,900
So let's have a nice command and then write something like Ways of Creating.

21
00:01:58,460 --> 00:01:59,090
Strain.

22
00:01:59,710 --> 00:02:02,080
Well, we have two ways of doing that.

23
00:02:02,080 --> 00:02:07,740
The first method is what you call using the string literature, and now one we have done before.

24
00:02:07,750 --> 00:02:15,970
So let's say that I want to create a string with a keyword const and my variable name, say my name

25
00:02:15,970 --> 00:02:23,050
and then it's equal to then the name I want to use as my name I will say John.

26
00:02:23,350 --> 00:02:30,160
So we see that I can now write or create a string using this quotation mark on them.

27
00:02:30,160 --> 00:02:33,550
So this shows that it's a string, it's a first method.

28
00:02:33,550 --> 00:02:36,040
So if I console.log it, you're going to see John.

29
00:02:36,370 --> 00:02:43,660
Okay, the next method is what you call using the using the constructor.

30
00:02:44,790 --> 00:02:45,630
Function.

31
00:02:46,440 --> 00:02:48,570
So the first one is using.

32
00:02:51,380 --> 00:02:52,550
Strength literature.

33
00:02:54,290 --> 00:02:59,570
So let's talk about how to create a function using the constructor function.

34
00:02:59,570 --> 00:03:06,470
So the same process, my variable name called const and I'll call this one as first name.

35
00:03:06,530 --> 00:03:08,120
And now here we go.

36
00:03:08,150 --> 00:03:12,050
Then I'll bring in new and then string.

37
00:03:12,860 --> 00:03:14,750
Uppercase S for string.

38
00:03:14,750 --> 00:03:22,220
And inside here I can add any string that I can pass in any string that I want to create.

39
00:03:22,400 --> 00:03:27,470
So if you dive in more about JavaScript, we see that this is what you call a class.

40
00:03:27,470 --> 00:03:32,720
We are creating an instance of a string, but A1 is advanced topics.

41
00:03:32,720 --> 00:03:35,540
For now, let's see how to create a string.

42
00:03:35,540 --> 00:03:40,340
So our parsing here, let's say doe for the first name.

43
00:03:40,460 --> 00:03:47,120
So if I console.log this to join my name and first name, let's see the differences.

44
00:03:47,120 --> 00:03:50,390
Well, so let me console.log my name.

45
00:03:51,740 --> 00:03:57,020
My name and then the first name together.

46
00:03:57,020 --> 00:04:03,590
So let me open the console and now you see that I have the two.

47
00:04:03,620 --> 00:04:10,380
First one is John for this one and then the let me have this way.

48
00:04:10,460 --> 00:04:14,540
This one is for this one and then first name is for this.

49
00:04:14,540 --> 00:04:17,570
But we see that there are some differences.

50
00:04:17,779 --> 00:04:23,560
So which one do you think we should use or which one do you think is a preferred way to use?

51
00:04:23,570 --> 00:04:29,780
Well, let me show you here before coming back to this, let's see the differences between these two.

52
00:04:30,020 --> 00:04:38,450
Well, if you try to console.log for the meantime, let's pass in the same value for my name to this

53
00:04:38,450 --> 00:04:40,310
one also as John.

54
00:04:40,760 --> 00:04:46,430
So let's try to compare these two strings because the values are all string.

55
00:04:46,430 --> 00:04:53,420
But if you compare my name to my name and the first name, let's see if you're going to get what is

56
00:04:53,420 --> 00:04:54,860
called true or false.

57
00:04:54,860 --> 00:04:59,150
So let's assign the result to available call result.

58
00:04:59,270 --> 00:05:08,300
And now it's equal to is my name triple equal to first name because for this one it is checking for

59
00:05:08,300 --> 00:05:09,950
the type and a value.

60
00:05:09,950 --> 00:05:15,350
So if I console.log the result down here let's see.

61
00:05:15,440 --> 00:05:17,600
You see that I get false.

62
00:05:17,750 --> 00:05:22,910
But if I remove one equal sign here, then I save it.

63
00:05:22,910 --> 00:05:30,920
I get to remember what we talked about, about the double equality and then the triple equals sign for

64
00:05:30,920 --> 00:05:32,570
the double equal sign.

65
00:05:32,600 --> 00:05:34,340
It only check for the value.

66
00:05:34,370 --> 00:05:41,960
It doesn't take the data type into consideration, but for triple equal to it, check for type and then

67
00:05:41,960 --> 00:05:42,500
the value.

68
00:05:42,530 --> 00:05:43,850
That's what we have foreseeing.

69
00:05:44,150 --> 00:05:48,710
So here the value is the same by the type is different.

70
00:05:48,710 --> 00:05:50,210
So for this method.

71
00:05:51,070 --> 00:05:56,800
We always create an instance of a string out of an object.

72
00:05:56,830 --> 00:06:00,060
That's why you saw an object syntax.

73
00:06:00,070 --> 00:06:06,080
So if you try to console look, first name again, first name again, you can see that.

74
00:06:06,100 --> 00:06:10,090
Let's save it and see that we have a string.

75
00:06:10,090 --> 00:06:14,050
And then inside I have the value called John.

76
00:06:14,470 --> 00:06:20,020
So this this syntax create a string out of an object.

77
00:06:20,020 --> 00:06:22,870
So it tries to compare objects and a string.

78
00:06:22,900 --> 00:06:30,490
I'm going to be forced because objects are always parsed by reference, but string like this one is

79
00:06:30,490 --> 00:06:30,910
not.

80
00:06:30,940 --> 00:06:37,420
So the idea where to go and a shortest way to go is use the string literal.

