1
00:00:00,150 --> 00:00:06,600
If you like math, this is the lesson for you as we're going to be looking at JavaScript operators and

2
00:00:06,600 --> 00:00:09,820
we have seen a little bit of these in the earlier lessons.

3
00:00:09,820 --> 00:00:15,540
So we're going to be focusing on how to use operators, what are available or what operators are available

4
00:00:15,540 --> 00:00:19,420
and the order of arithmetic operators in JavaScript.

5
00:00:19,680 --> 00:00:26,760
So if you remember from high school or public school that there is an order when you are adding, subtracting,

6
00:00:26,760 --> 00:00:28,120
multiplying or division.

7
00:00:28,290 --> 00:00:31,050
So there's a standard order of operations.

8
00:00:31,200 --> 00:00:35,550
So we do adding, subtracting, multiplication and division.

9
00:00:35,670 --> 00:00:40,680
And if we want to change around that order, then we need to wrap it with brackets.

10
00:00:40,830 --> 00:00:46,250
And there's more information available about arithmetic operators at the Modula Developer Network.

11
00:00:46,500 --> 00:00:50,250
So they've got a great example here of two plus three minus one.

12
00:00:50,250 --> 00:00:51,560
Quick, what's the answer?

13
00:00:51,570 --> 00:00:54,330
It's for this one gets a little bit more complicated.

14
00:00:54,510 --> 00:00:57,440
So we have four times three divided by two.

15
00:00:57,780 --> 00:01:02,370
So the answer here is that we're doing multiplication and then division.

16
00:01:02,380 --> 00:01:04,290
So that's the order of operation.

17
00:01:04,440 --> 00:01:10,030
So four times three is 12, divided by two is outputting six.

18
00:01:10,290 --> 00:01:12,630
This one is also a little bit more complicated.

19
00:01:12,750 --> 00:01:17,700
And we're doing a modulus and then we're also multiplying by the exponential.

20
00:01:17,910 --> 00:01:21,120
So we are not going to be exploring that in the upcoming lesson.

21
00:01:21,210 --> 00:01:25,370
But you're welcome to try that out in your console and play around with it.

22
00:01:25,380 --> 00:01:30,990
And although we are looking at Modulus and we explain that more detail as we go through the lesson,

23
00:01:31,380 --> 00:01:32,770
also there's additions.

24
00:01:32,770 --> 00:01:34,860
So of course, addition, just adding it together.

25
00:01:35,040 --> 00:01:40,290
And then there was some of the additions with strings that we saw, which is also known as concatenation,

26
00:01:40,440 --> 00:01:44,190
where we do a five plus FU ends up as a string value.

27
00:01:44,370 --> 00:01:50,700
So JavaScript again is trying to convert these as best as possible to either numbers or strings and

28
00:01:50,700 --> 00:01:51,570
adding them together.

29
00:01:51,600 --> 00:01:56,340
So if we have a boolean value plus a number, we end up with additions to booleans, we end up with

30
00:01:56,340 --> 00:01:57,890
additions and so on.

31
00:01:58,050 --> 00:01:59,400
There's also subtraction.

32
00:01:59,410 --> 00:02:05,220
So when we're subtracting a number and if we're doing a string minus three, then we're being returned

33
00:02:05,220 --> 00:02:06,360
back on a number.

34
00:02:06,360 --> 00:02:09,690
And as we saw in the last lesson, that tries to convert the string to a number.

35
00:02:09,810 --> 00:02:12,540
So that's where we get non-moving return back.

36
00:02:12,840 --> 00:02:15,090
We also have a division.

37
00:02:15,090 --> 00:02:20,140
So we've got division by all the different values and then the values that are being returned.

38
00:02:20,160 --> 00:02:21,660
Multiplication, of course.

39
00:02:21,930 --> 00:02:22,830
So we have two times.

40
00:02:22,830 --> 00:02:26,100
Two is four negative, two times two is negative four.

41
00:02:26,250 --> 00:02:32,910
And then if we multiply a value and we get not a number, but if we multiply infinity, so remember,

42
00:02:32,910 --> 00:02:37,170
anything by a zero is going to be returned back as a zero.

43
00:02:37,170 --> 00:02:38,220
But we're getting infinity.

44
00:02:38,320 --> 00:02:39,110
That's not a number.

45
00:02:39,630 --> 00:02:41,370
So this is one of the things to keep in mind.

46
00:02:41,370 --> 00:02:47,160
But very rarely are you ever going to be working with infinity so you don't have to usually worry about

47
00:02:47,160 --> 00:02:47,500
that.

48
00:02:47,520 --> 00:02:50,060
And of course, we can't multiply a string by two.

49
00:02:50,070 --> 00:02:50,840
Doesn't make sense.

50
00:02:51,420 --> 00:02:55,950
The one that we did want to look at and that might be something that might you might be not be familiar

51
00:02:55,950 --> 00:02:58,290
with is the modular operator.

52
00:02:58,290 --> 00:03:01,610
And what this is, this is the remainder essentially.

53
00:03:02,160 --> 00:03:04,500
So we get the value.

54
00:03:04,500 --> 00:03:08,370
And if we do 12 modulus five, we end up with two.

55
00:03:08,370 --> 00:03:14,580
So two is the remainder that's remaining there after we divide 12 by five.

56
00:03:14,790 --> 00:03:18,620
So we get it goes in twice, but we get a remainder of two.

57
00:03:18,660 --> 00:03:22,110
So ten divided by five is the two sets.

58
00:03:22,110 --> 00:03:23,030
We're getting the remainder.

59
00:03:23,370 --> 00:03:28,140
So that one is a little bit confusing because it is the remember remainder and then there's some other

60
00:03:28,140 --> 00:03:30,920
operators that we're not going to be exploring within the lesson.

61
00:03:31,050 --> 00:03:34,440
So there's a lot of great information on Segan module, the developer network.

62
00:03:34,770 --> 00:03:36,810
So we do need to look at order.

63
00:03:36,810 --> 00:03:42,270
And that was something that we saw that we've got multiplication, division, addition, subtraction.

64
00:03:42,420 --> 00:03:48,090
So that's the order of precedence of operator precedence and again, referring to the module of the

65
00:03:48,120 --> 00:03:49,170
developer network.

66
00:03:49,350 --> 00:03:51,990
So we get three plus four times five.

67
00:03:51,990 --> 00:03:53,190
Quick, what's the answer?

68
00:03:53,370 --> 00:04:01,590
OK, three plus four, seven times five would be 35, but we forgot the order of precedence, the operator

69
00:04:01,590 --> 00:04:02,190
precedence.

70
00:04:02,430 --> 00:04:04,290
So we're doing multiplication first.

71
00:04:04,290 --> 00:04:08,700
So four times five is 20 and then plus three.

72
00:04:08,830 --> 00:04:10,830
And that's why our answer is twenty three.

73
00:04:11,160 --> 00:04:16,110
So it does take some getting used to unless you're familiar with it from high school or public school,

74
00:04:16,680 --> 00:04:18,840
the order is still the same thing.

75
00:04:18,840 --> 00:04:25,560
And if we did want to do three plus four multiplied by five, that means that we would have to wrap

76
00:04:25,560 --> 00:04:26,280
it in brackets.

77
00:04:26,430 --> 00:04:28,890
And I'll show you quickly how that works in the console.

78
00:04:29,040 --> 00:04:36,090
So if we take a value and if we take the three rapide in brackets and then we multiply it by five,

79
00:04:36,240 --> 00:04:37,650
we're going to get 35.

80
00:04:37,980 --> 00:04:45,960
Whereas if we have three plus four times five, we're going to end up with twenty three and you get

81
00:04:45,960 --> 00:04:46,500
the picture.

82
00:04:46,530 --> 00:04:51,960
So wrapping it in brackets, just like you do with regular math outside of coding, it's going to work

83
00:04:51,960 --> 00:04:52,530
the same way.

84
00:04:52,620 --> 00:04:58,020
So keep in mind that there is an order and if you are doing some math and if you're not getting the

85
00:04:58,020 --> 00:04:59,460
value that you're expecting.

86
00:04:59,780 --> 00:05:05,720
Take a look at the order that it's being presented in there's the modulus, so we did look at this and

87
00:05:05,720 --> 00:05:12,710
I know 12 modulus five returning of two is a little bit confusing because it also means that five goes

88
00:05:12,710 --> 00:05:13,970
into 12 twice.

89
00:05:14,240 --> 00:05:17,510
So there we that number is a little bit confusing.

90
00:05:17,510 --> 00:05:24,440
But if we do 13, modulus five, you're going to see that we're returning back a value of three and

91
00:05:24,500 --> 00:05:25,170
a little bit with it.

92
00:05:25,190 --> 00:05:29,940
So we've got 13 modulus five and you see that the return is three.

93
00:05:30,110 --> 00:05:32,360
So 14 modulus five.

94
00:05:32,360 --> 00:05:33,290
What's the answer?

95
00:05:33,320 --> 00:05:35,630
Quick four and five.

96
00:05:35,630 --> 00:05:36,860
Modulus five.

97
00:05:37,070 --> 00:05:38,830
And what's the answer going to be?

98
00:05:38,870 --> 00:05:42,160
This is maybe a little bit of a trick question, but that's a zero.

99
00:05:42,200 --> 00:05:45,770
So try out some of the formulas, try some of the math operators.

100
00:05:45,770 --> 00:05:49,820
Remember the order of precedence, challenge yourself, have some fun with it.

101
00:05:49,850 --> 00:05:54,950
We're going to jump in the next lesson going into more detail about operators that are available in

102
00:05:54,950 --> 00:05:55,490
JavaScript.
