1
00:00:00,290 --> 00:00:07,850
Let's talk about assignment operators in JavaScript, which includes the following.

2
00:00:07,880 --> 00:00:10,940
So back to Visual Studio code.

3
00:00:10,970 --> 00:00:19,490
The first one is what we call the assignment operator, and I'm going to paste the description with

4
00:00:19,490 --> 00:00:21,140
some case study.

5
00:00:21,440 --> 00:00:29,360
So over here I'm going to add a comment and that is the assignment operators.

6
00:00:29,360 --> 00:00:34,340
And the first one is to use the equal to sign.

7
00:00:34,610 --> 00:00:39,920
And it says that this is used to assign value to a variable.

8
00:00:39,920 --> 00:00:45,590
And this is what we have used from the beginning of this course till this point.

9
00:00:45,590 --> 00:00:52,340
Anytime we want to assign a value to a variable, we use the assignment operator.

10
00:00:52,340 --> 00:00:57,370
And this is the most common use operators in JavaScript.

11
00:00:57,380 --> 00:00:59,710
So let's look at the case study.

12
00:00:59,720 --> 00:01:05,250
Let's say that you purchased ten apples from the grocery store.

13
00:01:05,340 --> 00:01:11,850
How can you use JavaScript to track of how many apples that you have?

14
00:01:11,880 --> 00:01:20,400
So here is going to be as simple as ABC by declaring a variable called total apples.

15
00:01:21,560 --> 00:01:24,080
And is equal to ten.

16
00:01:25,160 --> 00:01:29,240
As you can see here, that we have the underline.

17
00:01:29,810 --> 00:01:37,580
And one thing that I did not tell you is that in JavaScript, you cannot really declare a variable that

18
00:01:37,580 --> 00:01:39,530
has been declared already.

19
00:01:39,560 --> 00:01:44,600
If you scroll up here, we have the same variable name being declared.

20
00:01:44,600 --> 00:01:53,540
So we cannot reassign, so we can change this one to my total apples or something different.

21
00:01:53,540 --> 00:01:59,720
So let me change this one to my total apples and I will use camel casing here.

22
00:01:59,720 --> 00:02:04,070
And if you console log, my total apples is going to be ten.

23
00:02:04,430 --> 00:02:09,699
Then the next operator is to use the plus equal sign.

24
00:02:09,710 --> 00:02:12,620
So I'm going to copy this.

25
00:02:13,660 --> 00:02:19,210
Assignment operator using plus and then the equal sign.

26
00:02:19,630 --> 00:02:24,610
And we have used this one under the arithmetic operators.

27
00:02:24,610 --> 00:02:27,790
So let's see how we are going to use.

28
00:02:27,970 --> 00:02:34,770
First step is let me provide the description so that you can follow along pretty easily.

29
00:02:34,780 --> 00:02:44,410
This is used to add value on the right to the variable on the left and then assign the result to the

30
00:02:44,410 --> 00:02:46,030
variable on the left.

31
00:02:46,300 --> 00:02:51,520
Let's have some case study here so that you better understand.

32
00:02:51,640 --> 00:02:54,430
And this is the case study.

33
00:02:55,220 --> 00:03:03,230
As the mayor of a small town, the current population of your town is 100.

34
00:03:03,470 --> 00:03:09,500
But during this year, an additional 50 people moved to your town.

35
00:03:09,620 --> 00:03:14,270
How would you calculate the total population now?

36
00:03:14,390 --> 00:03:16,280
And here we go.

37
00:03:16,460 --> 00:03:19,010
Let's look at the variable names here.

38
00:03:19,280 --> 00:03:21,800
So here we have population.

39
00:03:21,800 --> 00:03:29,390
So we can say that let the population equal to 100.

40
00:03:29,980 --> 00:03:34,030
And this year it has increased by 50.

41
00:03:34,210 --> 00:03:41,980
So now we can redeclare this variable as plus equal to 50.

42
00:03:42,010 --> 00:03:47,470
And if we console log the population, let's have a look.

43
00:03:47,470 --> 00:03:49,300
And we have 150.

44
00:03:49,980 --> 00:03:58,200
But if you use const one more time, you're going to have error because we cannot re update a variable

45
00:03:58,200 --> 00:04:00,060
declared using const.

46
00:04:00,940 --> 00:04:07,060
And the next type of the arithmetic operator is using the minus.

47
00:04:07,270 --> 00:04:09,730
And let me copy this.

48
00:04:10,090 --> 00:04:14,080
And down here, paste it and change this one to minus.

49
00:04:14,080 --> 00:04:16,720
And I'm going to be the opposite way.

50
00:04:16,930 --> 00:04:21,310
So let's look at the case study so that you better understand.

51
00:04:21,760 --> 00:04:32,710
You have $200 in your wallet, and after buying a book for $30, how can you calculate how much money

52
00:04:32,740 --> 00:04:35,020
you now have in your wallet?

53
00:04:35,380 --> 00:04:39,220
So you can pause this video and give it a shot.

54
00:04:39,250 --> 00:04:41,290
Otherwise, let's continue.

55
00:04:41,440 --> 00:04:53,860
So based on this, we can deduce the variables names here as money in wallet and is equal to 200.

56
00:04:54,130 --> 00:04:59,260
And if I have used $30, how am I going to calculate?

57
00:04:59,290 --> 00:05:05,570
And for this we have a couple of ways we can use something like this as let.

58
00:05:07,280 --> 00:05:09,680
Money in wallet.

59
00:05:10,840 --> 00:05:18,760
Let me say money in wallet left is equal to 200 -30.

60
00:05:19,150 --> 00:05:21,760
And if I console log.

61
00:05:23,250 --> 00:05:28,170
Money in wallet and that is the money in wallet left.

62
00:05:28,950 --> 00:05:39,630
We have 117 but if you use the minus and equal sign is going to be as this money in wallet minus equal

63
00:05:39,630 --> 00:05:41,310
to 30.

64
00:05:41,890 --> 00:05:44,760
And it is same as before.

65
00:05:44,770 --> 00:05:49,480
So if you console.log money in wallet, we have won 70.

66
00:05:49,890 --> 00:05:50,290
Cool.

67
00:05:50,320 --> 00:05:50,950
Right?

68
00:05:50,950 --> 00:06:00,220
And the next type is the using multiplication sign and then the equal sign and you're going to be the

69
00:06:00,220 --> 00:06:01,350
same format.

70
00:06:01,360 --> 00:06:04,420
So let's look at the case study here.

71
00:06:04,540 --> 00:06:06,400
And it goes like this.

72
00:06:06,400 --> 00:06:15,370
You have 12 cookies and you decided to break each one into three pieces to share with your friends.

73
00:06:15,370 --> 00:06:21,760
How would you calculate the total number of cookie pieces that you have now?

74
00:06:21,850 --> 00:06:27,700
And it's going to be using the multiplication and then the equal sign.

75
00:06:27,940 --> 00:06:33,280
And for this I'm going to declare a variable called cookies in Java.

76
00:06:33,400 --> 00:06:39,130
So here cookies in Java is equal to 12.

77
00:06:39,850 --> 00:06:50,740
And I will say cookies in Java is I'm going to update that one using multiplication sign equal to and

78
00:06:50,740 --> 00:06:52,270
multiply by three.

79
00:06:52,540 --> 00:06:57,940
So with this one, if I save it and check cookies in Java.

80
00:06:59,780 --> 00:07:00,290
Is it?

81
00:07:00,290 --> 00:07:01,670
Cookies?

82
00:07:02,910 --> 00:07:03,660
Enjoy.

83
00:07:03,900 --> 00:07:05,760
And we have 36.

84
00:07:06,000 --> 00:07:06,540
Great.

85
00:07:06,540 --> 00:07:11,100
Or I can multiply this one by three.

86
00:07:11,910 --> 00:07:14,150
And I can remove this.

87
00:07:14,160 --> 00:07:20,220
The result is the same, but this is the shortest syntax.

88
00:07:20,550 --> 00:07:21,300
All right, cool.

89
00:07:21,300 --> 00:07:24,480
So let me undo and bring back to the.

90
00:07:25,310 --> 00:07:26,300
This one.

91
00:07:26,990 --> 00:07:28,090
All right.

92
00:07:28,100 --> 00:07:31,550
And next one is the division assignment.

93
00:07:31,550 --> 00:07:33,140
And you're going to be assessed.

94
00:07:33,650 --> 00:07:39,410
The difference here is we use different symbols before the equal sign.

95
00:07:39,740 --> 00:07:43,310
So for this, let's provide this scenario.

96
00:07:43,340 --> 00:07:51,950
It says that you have 200 page book that you want to study over the next five days, planning to read

97
00:07:51,950 --> 00:07:54,530
the same number of pages each day.

98
00:07:54,560 --> 00:07:59,620
How would you calculate how many pages you need to read each day?

99
00:07:59,630 --> 00:08:01,750
And we're going to be division, right?

100
00:08:01,760 --> 00:08:05,600
So here is going to be total pages.

101
00:08:05,600 --> 00:08:10,910
And remember, we have this variable name up here as total pages.

102
00:08:10,910 --> 00:08:17,720
So now we can change the name here as my total pages.

103
00:08:18,680 --> 00:08:24,920
And is equal to 200 and total pages.

104
00:08:24,920 --> 00:08:27,740
That is my total pages.

105
00:08:28,640 --> 00:08:36,010
I have to change this one to use let because we are updating a divided and equal to five.

106
00:08:36,020 --> 00:08:42,650
And if I console log my total pages, we have 40.

107
00:08:42,679 --> 00:08:50,150
Then we have the remainder or the module operator for this one too.

108
00:08:50,150 --> 00:08:51,410
We have explained it.

109
00:08:51,410 --> 00:08:54,410
So let's provide the case study and let's have a look.

110
00:08:54,440 --> 00:09:02,330
It says that you have 25 concert tickets that you want to distribute equally among four friends.

111
00:09:02,330 --> 00:09:09,050
How would you calculate the number of leftover ticket when you hear leftover meaning the remainder?

112
00:09:09,050 --> 00:09:17,330
Therefore, we are going to use the module operator and it goes like this let ticket and we have that

113
00:09:17,430 --> 00:09:21,960
one already and is equal to 25.

114
00:09:22,260 --> 00:09:26,730
I think we don't have ticket here being declared so we can go ahead and use this.

115
00:09:26,940 --> 00:09:37,050
And next is we are going to use or update the ticket module then divided by four.

116
00:09:37,050 --> 00:09:44,100
And if you console log ticket, we have one remainder of one.

117
00:09:44,250 --> 00:09:49,650
The last one is the exponential for this.

118
00:09:49,650 --> 00:09:57,750
One example is two exponent three meaning to multiply itself three times.

119
00:09:57,840 --> 00:10:08,970
And let me provide the case study here as that in a math problem you are giving a base number of two

120
00:10:09,150 --> 00:10:14,010
and ask to raise this number to the power of four.

121
00:10:14,010 --> 00:10:16,080
How will you calculate this?

122
00:10:16,110 --> 00:10:23,730
Meaning that we are going to multiply two four times, meaning two exponent four.

123
00:10:23,820 --> 00:10:32,250
So we are going to use JavaScript to achieve this and it's going to be as let the base number equal

124
00:10:32,250 --> 00:10:32,910
to two.

125
00:10:33,580 --> 00:10:42,250
And we are going to use the exponent symbol and we're going to be as base and multiply two times is

126
00:10:42,250 --> 00:10:43,390
equal to four.

127
00:10:43,690 --> 00:10:46,180
And for this one, we're going to have 16.

128
00:10:46,180 --> 00:10:54,940
So this one means that to multiply by two, multiply by two, multiply by two, that is four times.

129
00:10:54,970 --> 00:10:55,420
Great.

130
00:10:55,420 --> 00:11:01,480
So now if I save this and check inside here, that is base.

131
00:11:01,480 --> 00:11:02,890
We have 16.

132
00:11:03,070 --> 00:11:03,550
Great.

133
00:11:03,550 --> 00:11:08,260
So guys, these are examples of the assignment operators.

