1
00:00:00,320 --> 00:00:03,830
Let's talk about string operators.

2
00:00:04,460 --> 00:00:08,900
Let's get back to Visual Studio code and let's get started.

3
00:00:08,930 --> 00:00:18,470
I'm going to copy this command and down here paste that and I will change this one to string operators.

4
00:00:19,060 --> 00:00:26,690
In JavaScript, we have one primary string operator and that is the plus operator.

5
00:00:26,710 --> 00:00:31,780
So here I'm going to put it inside bracket and start.

6
00:00:32,530 --> 00:00:41,290
And this one is used to combine two or more strings together and this is what we call concatenation.

7
00:00:41,710 --> 00:00:47,200
Let's have some case study here and I'm going to paste it as that.

8
00:00:47,530 --> 00:00:55,990
Let's consider a case where you want to create a personalized greeting message by combining a fixed

9
00:00:55,990 --> 00:00:59,620
greeting string with a variable name string.

10
00:01:00,210 --> 00:01:08,880
So here I'm going to declare a variable called greeting and it is equal to Hello.

11
00:01:10,120 --> 00:01:13,510
And our at comma and space here.

12
00:01:14,170 --> 00:01:19,810
When I save it prettier have formatted by adding double quotes around it.

13
00:01:20,600 --> 00:01:25,460
Then I'm going to declare a variable as first name.

14
00:01:26,020 --> 00:01:29,380
And is equal to Thomas.

15
00:01:29,440 --> 00:01:33,070
And I'm going to combine these strings together.

16
00:01:33,490 --> 00:01:43,000
And I'm going to declare a variable called message and is equal to greeting plus first name.

17
00:01:44,210 --> 00:01:49,160
If we console log the message we have.

18
00:01:49,160 --> 00:01:55,340
Hello from us and I can combine two or more strings together.

19
00:01:55,910 --> 00:01:58,880
I can add last name.

20
00:02:00,380 --> 00:02:02,240
Is equal to.

21
00:02:03,650 --> 00:02:08,900
She nybrua And I'm going to add to this.

22
00:02:08,900 --> 00:02:12,410
So it's going to be greetings plus.

23
00:02:15,380 --> 00:02:17,180
The last name.

24
00:02:17,600 --> 00:02:20,630
Save it and let's have a look at the message.

25
00:02:20,630 --> 00:02:22,370
And we have Thomas.

26
00:02:23,330 --> 00:02:26,240
But as you can see, we don't have spacing.

27
00:02:26,240 --> 00:02:35,930
So to be able to add space, what we can do is that we can bring it here space, save it, and let's

28
00:02:35,930 --> 00:02:36,920
check it out here.

29
00:02:36,920 --> 00:02:43,970
And indeed we have some spacing or we can avoid this spacing.

30
00:02:43,970 --> 00:02:48,440
And inside here we are going to add some spacing here.

31
00:02:48,680 --> 00:02:53,660
So it's going to be called space and we add the plus.

32
00:02:53,660 --> 00:03:00,590
This is what we call the concatenation and we have a new feature called template literal.

33
00:03:00,710 --> 00:03:05,900
So instead of using this plus plus, we have a better way of doing it.

34
00:03:05,900 --> 00:03:12,290
But don't worry, as you move on, you will learn more about ins and outs of JavaScript.

35
00:03:12,680 --> 00:03:19,020
So if I save it and check it out here, we have the same result.

36
00:03:19,350 --> 00:03:24,210
Next step is we can use the plus equal to.

37
00:03:24,660 --> 00:03:31,170
So here I'm going to make use of the plus equal to string operator.

38
00:03:31,850 --> 00:03:40,370
And this is often used with strings to append or concatenate strings to the end of existing string.

39
00:03:40,880 --> 00:03:42,560
Let me show you an example here.

40
00:03:42,830 --> 00:03:48,770
Let's say we have a sentence which says, I love you.

41
00:03:49,910 --> 00:03:57,980
And if I want to add some string at the end, remember the increment and decrement.

42
00:03:58,190 --> 00:04:00,050
That is the data types.

43
00:04:00,800 --> 00:04:08,840
Do you remember under the arithmetic operators we can use plus equal sign and we can use the same on

44
00:04:08,840 --> 00:04:09,510
strings.

45
00:04:09,530 --> 00:04:17,420
So here I will bring in the sentence plus equal to let me add space here plus equal to.

46
00:04:17,420 --> 00:04:19,910
Then I will add JavaScript.

47
00:04:21,450 --> 00:04:22,440
With this one.

48
00:04:22,440 --> 00:04:30,150
What will be the result if I console.log sentence is going to be I love JavaScript, so let's check

49
00:04:30,150 --> 00:04:35,400
it out here a sentence and indeed I love JavaScript.

50
00:04:35,400 --> 00:04:38,580
So how can we add some spacing here?

51
00:04:38,670 --> 00:04:49,440
We can add it here or we can remove that and over here we are going to add some spacing and it's going

52
00:04:49,440 --> 00:04:54,420
to be as code code here and space and space here.

53
00:04:54,420 --> 00:04:57,390
And I'm going to add plus here.

54
00:04:58,020 --> 00:04:59,190
With this one.

55
00:04:59,190 --> 00:05:01,320
Let's see the answer.

56
00:05:01,320 --> 00:05:06,000
And we have the formatted string as that.

57
00:05:06,570 --> 00:05:10,290
But take note about this, which is really important.

58
00:05:10,800 --> 00:05:19,890
When using the plus operator with a number and a string JavaScript will treat the number as a string

59
00:05:19,890 --> 00:05:22,620
and concatenate them together.

60
00:05:23,070 --> 00:05:25,020
Let me show you an example here.

61
00:05:25,350 --> 00:05:33,980
Let's declare a variable called value or some value, and I'm going to add string here and a number

62
00:05:33,990 --> 00:05:38,610
I will say there are and then I will add ten at the end.

63
00:05:39,570 --> 00:05:42,990
What will be the result is going to be there are ten.

64
00:05:43,610 --> 00:05:47,240
With this one if I check the value.

65
00:05:47,450 --> 00:05:52,730
And as you can see, all of them have been converted to a string.

66
00:05:53,360 --> 00:05:55,820
And if I change this 1 to 10.

67
00:05:56,960 --> 00:06:04,370
We are trying to add ten plus ten, but this is a string, so it's going to concat.

68
00:06:04,460 --> 00:06:06,050
So let's check it out.

69
00:06:06,080 --> 00:06:10,130
If we check the answer, we have 1010.

70
00:06:10,950 --> 00:06:14,100
And you should be mindful about this situation.

71
00:06:14,400 --> 00:06:21,540
So to be able to make sure that we are adding numbers together, we have a couple of methods on numbers

72
00:06:21,540 --> 00:06:22,500
or strings.

73
00:06:22,620 --> 00:06:26,610
But don't worry, as you move on, we are going to explore more.

74
00:06:27,000 --> 00:06:27,870
Great.

75
00:06:27,990 --> 00:06:33,300
So guys, these are examples of operators in JavaScript.

