1 00:00:00,540 --> 00:00:03,230 Hello and welcome to this video. 2 00:00:03,510 --> 00:00:04,520 In this video. 3 00:00:04,530 --> 00:00:13,970 I'll be introducing you to Javascript operator precedence operator precedence. 4 00:00:13,980 --> 00:00:24,580 Basically describes the order in which operations are performed in an arithmetic expression. 5 00:00:26,190 --> 00:00:31,890 The best way to show you this is by actually illustrating an example. 6 00:00:31,890 --> 00:00:40,520 So I've got my Consul here so I'm going to create a variable and then to create a variable Hord. 7 00:00:41,120 --> 00:00:44,020 J You could call your variable anything. 8 00:00:44,110 --> 00:00:48,360 I'm going to give it a value of 150 9 00:00:51,750 --> 00:00:52,470 plus 10 00:00:54,840 --> 00:00:55,950 11 00:00:58,410 --> 00:01:01,670 and multiply by four. 12 00:01:01,680 --> 00:01:05,790 This is going to be in value for my variable called J. 13 00:01:05,810 --> 00:01:11,180 Lo fi press enter and try call this variable by name. 14 00:01:11,550 --> 00:01:15,910 Is going to give me a value of 430. 15 00:01:16,020 --> 00:01:21,190 Now if you used a calculator you get a different result. 16 00:01:21,480 --> 00:01:30,970 So if you put 150 plus 70 times four on your calculator it will return a value of eight hundred and 17 00:01:31,080 --> 00:01:31,890 eighty. 18 00:01:31,890 --> 00:01:40,350 The reason we get a different value here inside the console is that program in and also in Jaba script 19 00:01:40,470 --> 00:01:44,720 there is a precedence of operators. 20 00:01:44,970 --> 00:01:55,410 So what that basically means is that in terms of the order in which the operations perform multiplication 21 00:01:55,500 --> 00:02:01,980 and division have a higher precedence than addition subtraction. 22 00:02:02,220 --> 00:02:11,250 That is why the multiplication is done first so it will do the 70 times for first before it adds the 23 00:02:11,280 --> 00:02:12,420 150. 24 00:02:12,660 --> 00:02:16,540 So that is known as a precedent. 25 00:02:16,590 --> 00:02:22,360 So the president is out there where there is multiplication and division involved. 26 00:02:22,560 --> 00:02:31,620 It all take higher order than where there is addition subtraction involved so he does the multiplication 27 00:02:31,620 --> 00:02:33,040 first. 28 00:02:33,060 --> 00:02:39,210 Then the addition if there was division it would do that first and then the multiplication. 29 00:02:39,210 --> 00:02:44,240 There is a precedence in the operator action. 30 00:02:44,310 --> 00:02:51,150 However you can use parentheses to change that order. 31 00:02:51,210 --> 00:03:00,980 If you wanted the additions to be done first or you need to commit to a variable jihae and Winters said 32 00:03:00,990 --> 00:03:06,870 that two equates to a parent this is typee a 150 33 00:03:09,300 --> 00:03:12,480 plus 70 34 00:03:14,820 --> 00:03:19,870 and I will close in parenthesis. 35 00:03:20,250 --> 00:03:23,790 So what that does it will do the addition. 36 00:03:23,790 --> 00:03:30,370 First because I have wrapped it around the parent forces which gives it a higher order. 37 00:03:30,870 --> 00:03:36,240 Then I can now do the motts application. 38 00:03:36,240 --> 00:03:46,080 So if I do this return this variable it will now give me a value of eight hundred and eighty because 39 00:03:46,170 --> 00:03:55,640 I have forced the addition to compute that operation first before the multiplication is done. 40 00:03:55,830 --> 00:03:56,880 So I press enter. 41 00:03:56,910 --> 00:04:00,920 If I call the variable Jane now I should get eight. 42 00:04:01,050 --> 00:04:02,530 Which is me. 43 00:04:02,550 --> 00:04:03,900 Figure you will get. 44 00:04:04,050 --> 00:04:13,860 If you had used a standard calculator program in Javascript there is a precedence in the way the operator 45 00:04:13,890 --> 00:04:15,070 actions are performed. 46 00:04:15,070 --> 00:04:22,760 So if you want a particular operator to compute its value first you need to wrap it round parentheses 47 00:04:23,070 --> 00:04:28,140 and that would give it a higher order in the operator precedence. 48 00:04:28,380 --> 00:04:31,900 So that's basically how operate precedent works. 49 00:04:32,040 --> 00:04:33,360 Thank you for watching. 50 00:04:33,360 --> 00:04:34,160 Bye for now.