All language subtitles for 014 Basic Operators.en_US1

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:01,670 --> 00:00:04,930 Let's now learn some more JavaScript fundamentals. 2 00:00:04,930 --> 00:00:07,000 And in this video in particular, 3 00:00:07,000 --> 00:00:09,653 let's learn about some basic operators. 4 00:00:11,660 --> 00:00:15,760 And let's start by defining what an operator actually is. 5 00:00:15,760 --> 00:00:20,220 So an operator basically allows us to transform values 6 00:00:20,220 --> 00:00:22,530 or combine multiple values 7 00:00:22,530 --> 00:00:26,490 and really do all kinds of work with values. 8 00:00:26,490 --> 00:00:29,410 And there are many categories of operators 9 00:00:29,410 --> 00:00:33,000 like mathematical operators, comparison operators 10 00:00:33,000 --> 00:00:37,950 logical operators, assignment operators, and many more. 11 00:00:37,950 --> 00:00:38,830 So in this video, 12 00:00:38,830 --> 00:00:42,410 let's look at some of these types of operators 13 00:00:42,410 --> 00:00:47,160 starting with mathematical or arithmetic operators. 14 00:00:47,160 --> 00:00:50,370 So we already used the plus and minus operators 15 00:00:50,370 --> 00:00:53,860 but of course we can do all arithmetic operations. 16 00:00:53,860 --> 00:00:58,370 So we can also do multiplication, division and many more. 17 00:00:58,370 --> 00:01:01,650 And let's use the minus operator to calculate ages 18 00:01:01,650 --> 00:01:04,363 based on a person's birth year. 19 00:01:05,650 --> 00:01:10,650 So let's say ageJonas equals so the current year, 20 00:01:11,680 --> 00:01:15,890 and I will simply assume that right now it's 2037. 21 00:01:15,890 --> 00:01:17,990 So that's far in the future 22 00:01:17,990 --> 00:01:22,990 but let's make this a bit fun and then minus a birth year. 23 00:01:23,130 --> 00:01:25,163 So let's say 1991. 24 00:01:26,430 --> 00:01:27,263 Okay. 25 00:01:27,263 --> 00:01:32,067 And then let's just quickly log it to the console. 26 00:01:33,200 --> 00:01:36,803 So ageJonas using the auto-completion here. 27 00:01:39,280 --> 00:01:44,280 And so my age is 46, at least if we are currently in 2037. 28 00:01:46,360 --> 00:01:47,203 Okay. 29 00:01:48,510 --> 00:01:52,430 Now let's do the same for someone else. 30 00:01:52,430 --> 00:01:54,200 So let's say ageSarah 31 00:01:55,850 --> 00:01:57,090 and notice how we're using 32 00:01:57,090 --> 00:02:00,740 nicely descriptive variable names here. 33 00:02:00,740 --> 00:02:04,240 So the age of Jonas and the age of Sarah, 34 00:02:04,240 --> 00:02:08,820 instead of, for example, saying age one and age two. 35 00:02:08,820 --> 00:02:12,007 So again, right now it's 2037 36 00:02:12,007 --> 00:02:15,263 and then let's say Sarah was born in 2018. 37 00:02:16,360 --> 00:02:19,120 So let's log her age to the console as well. 38 00:02:19,120 --> 00:02:22,550 And we could now write the same line as this. 39 00:02:22,550 --> 00:02:24,400 So again, console.log 40 00:02:24,400 --> 00:02:28,080 but we can actually also log multiple values 41 00:02:28,080 --> 00:02:29,730 at the same time. 42 00:02:29,730 --> 00:02:32,290 So for that we just write a comma like this, 43 00:02:32,290 --> 00:02:35,700 and then the second value. 44 00:02:35,700 --> 00:02:39,310 And we could do even more by adding more commas. 45 00:02:39,310 --> 00:02:41,360 So here we could then log something else. 46 00:02:42,430 --> 00:02:43,423 Give it a save. 47 00:02:44,680 --> 00:02:48,960 And so here we see now 46 and 19 years. 48 00:02:48,960 --> 00:02:49,793 Great. 49 00:02:49,793 --> 00:02:52,130 So that's how we used the minus operator 50 00:02:52,130 --> 00:02:54,280 to solve a very simple problem 51 00:02:54,280 --> 00:02:57,950 in this case, simply to calculate an age. 52 00:02:57,950 --> 00:03:00,760 However, we can actually do better here. 53 00:03:00,760 --> 00:03:02,990 That's because we have this value here 54 00:03:02,990 --> 00:03:04,850 that is repeating itself. 55 00:03:04,850 --> 00:03:09,740 So this year 2037 is appearing both here and here. 56 00:03:09,740 --> 00:03:14,080 And so that's not good because we are repeating this value. 57 00:03:14,080 --> 00:03:15,900 So if the year now changes 58 00:03:15,900 --> 00:03:19,160 then we would have to change it in these both places. 59 00:03:19,160 --> 00:03:20,970 And we don't like that. 60 00:03:20,970 --> 00:03:24,760 And so that's why we have the concept of variables. 61 00:03:24,760 --> 00:03:27,380 So instead of having this value here, 62 00:03:27,380 --> 00:03:32,380 let's say now and then we assign this value 63 00:03:33,670 --> 00:03:35,990 to the now variable. 64 00:03:35,990 --> 00:03:36,850 Okay. 65 00:03:36,850 --> 00:03:40,500 And notice how I'm always by default using const. 66 00:03:40,500 --> 00:03:41,333 Okay. 67 00:03:41,333 --> 00:03:42,870 And that's because I'm not changing 68 00:03:42,870 --> 00:03:46,480 any of these variables here anywhere in my code. 69 00:03:46,480 --> 00:03:49,703 Only if I needed to change them, I would switch to that. 70 00:03:51,130 --> 00:03:55,400 Okay. And now here I can replace this one with now 71 00:03:57,160 --> 00:04:02,160 and this one and it should work the same and it does. 72 00:04:02,200 --> 00:04:03,033 Great. 73 00:04:03,033 --> 00:04:07,203 So that's a very good use case for a variable right there. 74 00:04:09,260 --> 00:04:10,480 And of course we can use 75 00:04:10,480 --> 00:04:13,403 all kinds of different math operations. 76 00:04:16,360 --> 00:04:18,450 So let's say console.log 77 00:04:19,340 --> 00:04:20,980 and now we could go ahead into 78 00:04:20,980 --> 00:04:24,500 ageJonas times two, 79 00:04:24,500 --> 00:04:27,723 so using this asterisk or star, 80 00:04:28,630 --> 00:04:30,170 or we could also do 81 00:04:30,170 --> 00:04:34,750 ageJonas and divided by two, 82 00:04:34,750 --> 00:04:38,150 and notice how these are two different calculations here. 83 00:04:38,150 --> 00:04:39,750 So one calculation 84 00:04:39,750 --> 00:04:41,360 and another one, 85 00:04:41,360 --> 00:04:43,600 or basically another operation. 86 00:04:43,600 --> 00:04:46,000 And that's because as I mentioned before, 87 00:04:46,000 --> 00:04:49,000 we can log different values at the same time 88 00:04:49,000 --> 00:04:50,583 in one console.log. 89 00:04:51,470 --> 00:04:54,080 So here we are creating one value 90 00:04:54,080 --> 00:04:56,143 and here we are creating a second value. 91 00:04:57,210 --> 00:04:58,760 Let's actually divide it by 10 92 00:05:00,470 --> 00:05:04,583 and then let's also use the exponentiation operator. 93 00:05:05,610 --> 00:05:10,610 So for example, two to the power of three, okay. 94 00:05:11,230 --> 00:05:15,023 And here we can use a comment to explain what this means. 95 00:05:16,620 --> 00:05:18,970 So that's a nice use case. 96 00:05:18,970 --> 00:05:23,970 So three means two to the power of three, 97 00:05:25,400 --> 00:05:30,310 which is equal to two times two times two. 98 00:05:30,310 --> 00:05:32,940 So three times this, 99 00:05:32,940 --> 00:05:35,493 so this should be eight, right? 100 00:05:37,170 --> 00:05:38,500 Let's try that. 101 00:05:38,500 --> 00:05:43,500 And indeed 46, which is Jonas' age, times two is 92, 102 00:05:45,650 --> 00:05:47,213 then divided by six is 4.6. 103 00:05:49,436 --> 00:05:51,017 So that's this. 104 00:05:51,017 --> 00:05:55,090 And then two to the power of three is indeed eight. 105 00:05:55,090 --> 00:05:55,923 Nice. 106 00:05:57,950 --> 00:06:00,530 Next, there is another use case 107 00:06:00,530 --> 00:06:03,630 that we didn't use yet for the plus operator. 108 00:06:03,630 --> 00:06:06,280 And that's because we can use the plus operator 109 00:06:06,280 --> 00:06:07,950 to join strings, 110 00:06:07,950 --> 00:06:11,453 or in other words, to concatenate different strings. 111 00:06:12,290 --> 00:06:14,820 So let's create two variables, 112 00:06:14,820 --> 00:06:19,350 firstName equals Jonas 113 00:06:22,140 --> 00:06:27,123 and lastName equals Schmedtmann. 114 00:06:28,980 --> 00:06:33,690 And now I can concatenate these two strings using plus. 115 00:06:33,690 --> 00:06:36,700 So let's log that to the console. 116 00:06:36,700 --> 00:06:40,813 So firstName plus lastName. 117 00:06:44,690 --> 00:06:46,710 And let's see. 118 00:06:46,710 --> 00:06:50,060 And indeed we have now one big string 119 00:06:50,060 --> 00:06:53,050 with both of the names together. 120 00:06:53,050 --> 00:06:56,060 So both of the strings that we declared earlier. 121 00:06:56,060 --> 00:06:59,480 But what if we wanted a space in between there? 122 00:06:59,480 --> 00:07:01,500 Well, that's not too hard. 123 00:07:01,500 --> 00:07:04,160 All we need to do is to create another string 124 00:07:04,160 --> 00:07:06,020 which is just a space 125 00:07:06,020 --> 00:07:09,700 and then concatenate it here with these two. 126 00:07:09,700 --> 00:07:11,580 And we can actually do that right here. 127 00:07:11,580 --> 00:07:14,060 So we want this string, 128 00:07:14,060 --> 00:07:16,310 firstName which is just Jonas. 129 00:07:16,310 --> 00:07:18,340 Remember the JavaScript engine 130 00:07:18,340 --> 00:07:22,173 will simply replace this string with this one. 131 00:07:23,030 --> 00:07:25,210 Then we create an empty string 132 00:07:26,490 --> 00:07:28,750 or actually a string with a space 133 00:07:28,750 --> 00:07:32,180 and then we add that one to lastName. 134 00:07:32,180 --> 00:07:37,180 So that's gonna be Jonas plus a space plus Schmedtmann. 135 00:07:38,900 --> 00:07:39,733 Let's see. 136 00:07:40,680 --> 00:07:45,600 And indeed that's exactly the result that we were after. 137 00:07:45,600 --> 00:07:47,400 Now there's actually a better way 138 00:07:47,400 --> 00:07:51,260 of doing this kind of concatenation of strings, 139 00:07:51,260 --> 00:07:53,470 which is called template strings, 140 00:07:53,470 --> 00:07:56,110 but let's focus on operators now. 141 00:07:56,110 --> 00:07:56,950 Okay. 142 00:07:56,950 --> 00:07:58,810 So this is a very useful one 143 00:07:58,810 --> 00:08:01,023 that we actually use quite often. 144 00:08:02,300 --> 00:08:04,050 So another type of operator 145 00:08:04,050 --> 00:08:06,340 is actually the typeof operator, 146 00:08:06,340 --> 00:08:08,860 which we already used up here. 147 00:08:08,860 --> 00:08:10,653 So I'm not gonna do that again. 148 00:08:11,750 --> 00:08:16,740 So remember here we had the typeof operator 149 00:08:16,740 --> 00:08:20,740 and that would then give us the type of the value. 150 00:08:20,740 --> 00:08:23,030 So we already know how that one works. 151 00:08:23,030 --> 00:08:25,220 So let's move on to the next category, 152 00:08:25,220 --> 00:08:27,970 which are assignment operators. 153 00:08:27,970 --> 00:08:30,800 And the most straightforward assignment operator 154 00:08:30,800 --> 00:08:32,700 is just the equal sign. 155 00:08:32,700 --> 00:08:34,580 So let's say, 156 00:08:34,580 --> 00:08:39,550 let x equal 10 plus five. 157 00:08:39,550 --> 00:08:44,150 And so this equal sign here is actually itself an operator, 158 00:08:44,150 --> 00:08:45,000 alright? 159 00:08:45,000 --> 00:08:48,290 So in this line of code, we do actually have two operators. 160 00:08:48,290 --> 00:08:51,143 We have the plus and then the equal. 161 00:08:52,170 --> 00:08:55,610 Now in this case, x will be assigned 15 162 00:08:55,610 --> 00:08:57,950 because the plus operator is executed 163 00:08:57,950 --> 00:09:01,350 before the assignment operator, okay? 164 00:09:01,350 --> 00:09:03,490 And that's based on a couple of rules 165 00:09:03,490 --> 00:09:06,500 about operator proceedings that I'm gonna show you 166 00:09:06,500 --> 00:09:07,853 in the next video. 167 00:09:12,390 --> 00:09:14,760 So let me actually show that to you 168 00:09:14,760 --> 00:09:18,530 that it indeed works as I told you. 169 00:09:18,530 --> 00:09:20,243 And yeah, so it's 15. 170 00:09:21,330 --> 00:09:24,100 So 10 plus five is done first 171 00:09:24,100 --> 00:09:26,380 and then the result of this operation, 172 00:09:26,380 --> 00:09:29,960 which is 15, will then be assigned to x. 173 00:09:29,960 --> 00:09:32,960 And so that itself is another operator 174 00:09:32,960 --> 00:09:35,540 but there are more assignment operators. 175 00:09:35,540 --> 00:09:39,830 So let me show one to you, which is this one, 176 00:09:39,830 --> 00:09:43,960 x plus equal 10. 177 00:09:43,960 --> 00:09:47,260 So we know that at this point after this line 178 00:09:47,260 --> 00:09:49,480 x is 15, right? 179 00:09:49,480 --> 00:09:51,800 So let's write that as a comment. 180 00:09:51,800 --> 00:09:53,720 And then we have this next line. 181 00:09:53,720 --> 00:09:57,150 So this weird x plus equal. 182 00:09:57,150 --> 00:10:00,010 So what does plus equal actually mean? 183 00:10:00,010 --> 00:10:03,800 Well, let's write that again as a comment. 184 00:10:03,800 --> 00:10:08,463 So what this means is x equal x plus 10. 185 00:10:09,770 --> 00:10:11,880 So instead of having to write all of this, 186 00:10:11,880 --> 00:10:16,880 we can simply write x plus equal 10, all right? 187 00:10:17,327 --> 00:10:19,890 And so x should now be 25 188 00:10:19,890 --> 00:10:24,020 because this x year from the previous step is 15. 189 00:10:24,020 --> 00:10:28,200 So here we are basically reassigning the x value. 190 00:10:28,200 --> 00:10:30,280 That's why I used a let here. 191 00:10:30,280 --> 00:10:34,650 So again, x at this point here will be 15 192 00:10:34,650 --> 00:10:37,633 and then 15 plus 10 should be 25. 193 00:10:39,380 --> 00:10:41,773 And indeed it's now 25. 194 00:10:45,430 --> 00:10:48,880 So let's write that result here so that we can keep track 195 00:10:48,880 --> 00:10:50,940 as I show you more operators, 196 00:10:50,940 --> 00:10:52,670 because as you might imagine, 197 00:10:52,670 --> 00:10:55,170 there are more operators like this. 198 00:10:55,170 --> 00:11:00,170 For example, there is x and then times equal four. 199 00:11:01,050 --> 00:11:03,290 And I hope you can imagine 200 00:11:03,290 --> 00:11:08,290 that this will mean x is equal x times four 201 00:11:10,470 --> 00:11:14,773 and this should be in this case 25 times four, so 100. 202 00:11:15,840 --> 00:11:19,870 Let's check and yes, it works. 203 00:11:19,870 --> 00:11:23,623 The same operator also exists with divided here, 204 00:11:24,730 --> 00:11:27,440 but I'm not gonna go into that one. 205 00:11:27,440 --> 00:11:32,240 So to finish, I will just show you the x plus plus operator. 206 00:11:32,240 --> 00:11:34,700 And what this will do is 207 00:11:34,700 --> 00:11:38,163 x equals x plus one. 208 00:11:39,030 --> 00:11:40,260 So let's see. 209 00:11:40,260 --> 00:11:41,937 And yes, we have 101. 210 00:11:45,130 --> 00:11:47,343 And we also have x minus minus. 211 00:11:48,570 --> 00:11:51,270 So if we do that twice now, 212 00:11:51,270 --> 00:11:53,020 what do you think will happen here? 213 00:11:55,530 --> 00:11:58,560 And indeed we get 99. 214 00:11:58,560 --> 00:12:00,400 So minus minus is basically 215 00:12:00,400 --> 00:12:03,060 just the opposite of plus plus. 216 00:12:03,060 --> 00:12:06,440 So this one will decrease the value by one 217 00:12:06,440 --> 00:12:08,793 and so we end up with 99. 218 00:12:10,940 --> 00:12:12,060 Okay. 219 00:12:12,060 --> 00:12:13,300 So let's actually write 220 00:12:13,300 --> 00:12:18,300 that these are assignment operators 221 00:12:19,680 --> 00:12:24,297 and these are, let's say math operators. 222 00:12:26,820 --> 00:12:31,820 And so now let's talk about comparison operators, 223 00:12:33,260 --> 00:12:35,320 and these are pretty great. 224 00:12:35,320 --> 00:12:38,060 So basically, we use comparison operators 225 00:12:38,060 --> 00:12:40,113 to produce Boolean values. 226 00:12:41,440 --> 00:12:43,350 So let me show you how that works 227 00:12:43,350 --> 00:12:45,230 and then I'm sure it will make sense 228 00:12:45,230 --> 00:12:47,870 that the result of a comparison operator 229 00:12:47,870 --> 00:12:49,740 should be a Boolean. 230 00:12:49,740 --> 00:12:52,950 So let's say we are trying to figure out 231 00:12:52,950 --> 00:12:57,950 if ageJonas is greater than ageSarah, right? 232 00:12:59,690 --> 00:13:02,460 So what could the result of this be 233 00:13:02,460 --> 00:13:04,950 if we think about this logically? 234 00:13:04,950 --> 00:13:09,650 So ageJonas can either be greater than Sarah or not. 235 00:13:09,650 --> 00:13:10,690 And so if it is greater 236 00:13:10,690 --> 00:13:13,300 then the result of this should be true 237 00:13:13,300 --> 00:13:14,390 and if it's not, 238 00:13:14,390 --> 00:13:16,313 then it should just be false. 239 00:13:17,660 --> 00:13:21,800 So indeed the result of this one is true 240 00:13:21,800 --> 00:13:26,410 that's because Jonas' age is 46 and Sarah is 19. 241 00:13:26,410 --> 00:13:30,327 So this is basically like asking the operator, 242 00:13:30,327 --> 00:13:34,510 "Is the age of Jonas greater than the age of Sarah?" 243 00:13:34,510 --> 00:13:38,040 And the operator will then essentially reply with 244 00:13:38,040 --> 00:13:40,780 yes, it is, which means true 245 00:13:40,780 --> 00:13:43,910 or no, it's not, which means false. 246 00:13:43,910 --> 00:13:46,260 And this can be very useful later 247 00:13:46,260 --> 00:13:48,980 when we start taking decisions with our code 248 00:13:48,980 --> 00:13:51,710 based on conditions like this. 249 00:13:51,710 --> 00:13:52,660 Okay. 250 00:13:52,660 --> 00:13:55,690 Now of course there's also the less than, 251 00:13:55,690 --> 00:13:57,120 so the opposite, 252 00:13:57,120 --> 00:14:01,400 and also there is greater equal or less than equal. 253 00:14:01,400 --> 00:14:05,770 So basically we have this one and we have this one 254 00:14:05,770 --> 00:14:10,770 then we have greater equal and less than or equal. 255 00:14:12,720 --> 00:14:14,480 So let's see a nice application 256 00:14:14,480 --> 00:14:16,713 of the greater than equal operator. 257 00:14:19,070 --> 00:14:22,780 So let's say we wanted to test if Sarah is of full age. 258 00:14:22,780 --> 00:14:27,400 So that means that she must be at least 18 years old, 259 00:14:27,400 --> 00:14:30,380 and at least means that she is greater than 18 260 00:14:30,380 --> 00:14:32,600 or exactly 18. 261 00:14:32,600 --> 00:14:36,860 And so we can use the appropriate operator for that. 262 00:14:36,860 --> 00:14:40,403 So greater or equal 18. 263 00:14:41,280 --> 00:14:42,113 Okay. 264 00:14:42,113 --> 00:14:44,260 So 18 should already be included 265 00:14:44,260 --> 00:14:46,233 and that's why we have this equal here. 266 00:14:47,930 --> 00:14:49,623 So this should be true. 267 00:14:50,460 --> 00:14:52,700 And yes, it is. 268 00:14:52,700 --> 00:14:56,440 So if we make her one year younger, 269 00:14:56,440 --> 00:15:01,440 so let's say she was born in 2019, then her age is 18, 270 00:15:01,670 --> 00:15:02,990 as you see here, 271 00:15:02,990 --> 00:15:05,140 and she is still of full eight. 272 00:15:05,140 --> 00:15:06,910 So it's still true here. 273 00:15:06,910 --> 00:15:09,570 And that's because we included 18 here 274 00:15:09,570 --> 00:15:13,780 in the age basically by using this equal sign. 275 00:15:13,780 --> 00:15:18,770 But now if we made her born in 2020, she would be 17 276 00:15:18,770 --> 00:15:21,920 and then this should turn out to be false. 277 00:15:21,920 --> 00:15:26,300 So that's checked out and yes, now it's false. 278 00:15:26,300 --> 00:15:27,960 Great. 279 00:15:27,960 --> 00:15:31,520 Now keep in mind that in real development 280 00:15:31,520 --> 00:15:34,670 we would actually store these results here. 281 00:15:34,670 --> 00:15:38,420 So for example, the result of this comparison operator 282 00:15:38,420 --> 00:15:39,910 or this one year, 283 00:15:39,910 --> 00:15:42,610 we would store these results in variables 284 00:15:42,610 --> 00:15:46,100 and not just always lock the results to the console. 285 00:15:46,100 --> 00:15:47,010 Okay. 286 00:15:47,010 --> 00:15:48,840 But in this case, I just wanted to show 287 00:15:48,840 --> 00:15:50,410 how all of this works. 288 00:15:50,410 --> 00:15:51,610 And so we need to console 289 00:15:51,610 --> 00:15:54,950 because really all we want to do is to see the results 290 00:15:54,950 --> 00:15:56,860 because we're still learning. 291 00:15:56,860 --> 00:15:57,940 Okay. 292 00:15:57,940 --> 00:15:59,500 We could also just do all of this 293 00:15:59,500 --> 00:16:02,010 right here in the console immediately 294 00:16:02,010 --> 00:16:04,400 but then we would kind of lose the record 295 00:16:04,400 --> 00:16:05,920 of what we're learning 296 00:16:05,920 --> 00:16:09,510 and it would be not so easy to scroll up and down. 297 00:16:09,510 --> 00:16:10,343 Okay. 298 00:16:10,343 --> 00:16:15,343 But of course we could just do this, right. 299 00:16:15,760 --> 00:16:19,154 We could just write ageSarah greater or equal 18, 300 00:16:19,154 --> 00:16:21,104 and we would still get the same result. 301 00:16:22,020 --> 00:16:25,770 And this works because the console actually has access 302 00:16:25,770 --> 00:16:27,950 to all the variables that is running 303 00:16:27,950 --> 00:16:30,610 in the current browser tab, right. 304 00:16:30,610 --> 00:16:32,930 So all the variables that we have here 305 00:16:32,930 --> 00:16:35,130 like firstName, for example, 306 00:16:35,130 --> 00:16:36,720 they are all right here. 307 00:16:36,720 --> 00:16:38,223 Can even auto complete them. 308 00:16:39,230 --> 00:16:40,230 Okay. 309 00:16:40,230 --> 00:16:44,020 But then again, if we would reload this page now, 310 00:16:44,020 --> 00:16:46,233 then all we just did would be lost. 311 00:16:47,780 --> 00:16:50,233 And of course we could also simply as I said, 312 00:16:51,610 --> 00:16:53,550 just store these results 313 00:16:53,550 --> 00:16:56,040 if we needed them later in our code. 314 00:16:56,040 --> 00:17:01,040 so isFullAge and then we could do this. 315 00:17:03,090 --> 00:17:04,480 And so this variable 316 00:17:04,480 --> 00:17:07,940 would be the one holding the Boolean value then. 317 00:17:07,940 --> 00:17:10,130 And actually as you see here in this popup, 318 00:17:10,130 --> 00:17:14,010 vs code is so smart that it figures out automatically 319 00:17:14,010 --> 00:17:17,030 that this variable here is gonna be a Boolean 320 00:17:17,030 --> 00:17:19,550 because of the code that we wrote here 321 00:17:19,550 --> 00:17:22,693 which of course has a Boolean as a result. 322 00:17:24,610 --> 00:17:25,550 Okay. 323 00:17:25,550 --> 00:17:27,800 So now just to finish, 324 00:17:27,800 --> 00:17:32,010 let's say that we don't want the intermediate age variables 325 00:17:32,010 --> 00:17:34,530 and do this kind of comparison here, 326 00:17:34,530 --> 00:17:36,220 all in one go. 327 00:17:36,220 --> 00:17:37,053 So this here. 328 00:17:38,290 --> 00:17:40,653 So let me show that to you in the code. 329 00:17:42,570 --> 00:17:45,720 So again, imagine we have a lot of code 330 00:17:45,720 --> 00:17:50,100 and we don't want to calculate these ages here separately. 331 00:17:50,100 --> 00:17:51,300 So we could just do 332 00:17:51,300 --> 00:17:55,470 now minus 1991, 333 00:17:55,470 --> 00:18:00,470 and then test if it's greater than now, minus 2020. 334 00:18:02,450 --> 00:18:04,450 Well, let's actually put it back to 2019 335 00:18:05,800 --> 00:18:08,563 as we had before, or actually 2018 I think. 336 00:18:11,800 --> 00:18:16,300 So this now is basically just the same as this year. 337 00:18:16,300 --> 00:18:19,710 We simply are doing it now all in one step. 338 00:18:19,710 --> 00:18:24,550 So this code is the same as this as it's highlighted here. 339 00:18:24,550 --> 00:18:27,570 And this is the same as this one. 340 00:18:27,570 --> 00:18:29,500 And so this whole line of code 341 00:18:29,500 --> 00:18:32,550 is essentially the same as doing this. 342 00:18:32,550 --> 00:18:34,340 Now the big question here is, 343 00:18:34,340 --> 00:18:36,060 how does JavaScript know 344 00:18:36,060 --> 00:18:38,600 if it should do the math first 345 00:18:38,600 --> 00:18:41,860 or if it should do the comparison first, right? 346 00:18:41,860 --> 00:18:43,200 Because we could think 347 00:18:43,200 --> 00:18:47,270 that the first thing to do is to calculate this, 348 00:18:47,270 --> 00:18:49,380 so basically 46 349 00:18:49,380 --> 00:18:54,190 and then JavaScript could compare that 46 to now right away, 350 00:18:54,190 --> 00:18:55,190 right? 351 00:18:55,190 --> 00:18:56,130 That's what would happen 352 00:18:56,130 --> 00:18:59,453 if the operation would simply proceed from left to right. 353 00:19:00,880 --> 00:19:02,780 But we will see that it doesn't. 354 00:19:02,780 --> 00:19:07,290 So we will see that this actually works just fine, right. 355 00:19:07,290 --> 00:19:10,160 And so JavaScript has some way of knowing 356 00:19:10,160 --> 00:19:13,640 that it should first do this operation, 357 00:19:13,640 --> 00:19:15,060 then this one, 358 00:19:15,060 --> 00:19:17,070 so that it has the two numbers 359 00:19:17,070 --> 00:19:18,600 and then only at the end, 360 00:19:18,600 --> 00:19:20,420 once it has the two ages, 361 00:19:20,420 --> 00:19:23,670 it will compare them with this operator in the middle. 362 00:19:23,670 --> 00:19:25,450 So how does that work? 363 00:19:25,450 --> 00:19:28,120 Well, that's what we're gonna talk about, right, 364 00:19:28,120 --> 00:19:29,193 in the next video. 25775

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.