1 00:00:01,000 --> 00:00:06,710 Welcome back! Functions are the hardest part of JavaScript. 2 00:00:07,140 --> 00:00:11,380 And it will take some time to fully get it. However, 3 00:00:11,480 --> 00:00:13,810 in this video we're going to try and do that. 4 00:00:13,880 --> 00:00:18,020 We're going to learn JavaScript functions. 5 00:00:18,030 --> 00:00:21,710 So, let's start off with, "What are functions?" 6 00:00:22,640 --> 00:00:28,040 Well, they're piece of code, that perform actions. Without functions 7 00:00:28,040 --> 00:00:30,730 JavaScript wouldn't really do anything. 8 00:00:30,740 --> 00:00:40,340 The beauty is that functions can perform one action or multiple actions. But we'll get back to that. First, 9 00:00:40,390 --> 00:00:45,560 let's talk about how you already know some JavaScript functions without even realizing it. 10 00:00:45,640 --> 00:00:47,250 You've seen them before. 11 00:00:47,300 --> 00:00:53,160 'alert' - that's a function. 'prompt' - 12 00:00:56,130 --> 00:00:57,970 that's a function. 13 00:00:58,150 --> 00:00:59,350 You've seen these before. 14 00:01:00,240 --> 00:01:07,500 So, JavaScript provides for us some functions, that are really-really useful, so that everybody who writes 15 00:01:07,500 --> 00:01:12,380 JavaScript, can use them without having to write them over and over. 16 00:01:12,430 --> 00:01:15,700 So with functions we have 2 options. 17 00:01:15,830 --> 00:01:20,990 One - is using existing JavaScript functions, like 'alert' and 'prompt'. 18 00:01:21,980 --> 00:01:25,880 And two - we can create our own. 19 00:01:25,880 --> 00:01:32,900 So, before we get into how we create our own functions and what is so useful about them, you might have 20 00:01:32,900 --> 00:01:37,920 noticed - noticed one thing: these brackets, that are right next to each other with functions. 21 00:01:37,940 --> 00:01:45,800 What do they mean? Well, that in JavaScript means to execute the function. 22 00:01:46,840 --> 00:01:52,750 So, let's see if what happens, when I just type in 'alert' and press 'enter'. 23 00:01:52,810 --> 00:02:01,540 I get 'f alert()' and some weird stuff. Hmmm, 'f' over here stands for function and can see when I hover 24 00:02:01,540 --> 00:02:01,990 over it. 25 00:02:01,990 --> 00:02:04,450 It says 'function alert()'. 26 00:02:04,450 --> 00:02:08,060 This is what running a function means: in order to run 27 00:02:08,080 --> 00:02:08,960 'alert()' 28 00:02:09,009 --> 00:02:13,090 I execute it by calling it like this ['alert()'] 29 00:02:15,010 --> 00:02:23,330 So, these brackets mean 'calling a function', so I can call a function. 30 00:02:23,490 --> 00:02:28,580 And you also noticed, that within 'alert' I can add things like 31 00:02:29,050 --> 00:02:33,800 "hi there!" 32 00:02:33,910 --> 00:02:42,190 These are all called 'arguments' and I know, I'm throwing a bunch of jargon, a bunch of words at you, but these 33 00:02:42,190 --> 00:02:44,670 are just things that you'll hear over and over, 34 00:02:44,710 --> 00:02:51,490 when you're a developer, and they'll stick to you - it won't the first time, but, like I said, just try and 35 00:02:51,700 --> 00:02:53,990 get there one step at a time. 36 00:02:54,010 --> 00:02:58,630 So 'arguments' are what's given to functions. 37 00:02:58,840 --> 00:03:03,880 For example, when we did, in our example here. 38 00:03:03,970 --> 00:03:13,190 "Hellooooo" and the 'console.log' was an 'argument'. And the interesting thing is that you can have multiple arguments: 39 00:03:13,200 --> 00:03:19,820 for example, if I removed this and just have, let's just have 'console.log' for now. 40 00:03:20,190 --> 00:03:24,690 I can do "How are you". 41 00:03:24,700 --> 00:03:27,950 I save and refresh and I get. 42 00:03:27,950 --> 00:03:29,150 "Hellooooo How are you". 43 00:03:29,210 --> 00:03:37,800 See, I can have multiple arguments, but just adding a comma. But again, that depends on the function. 44 00:03:37,810 --> 00:03:47,870 Now, again before we start creating our own, let's review. 'alert' is a function, 'alert' with the brackets, 45 00:03:47,960 --> 00:03:56,220 I'm calling the 'alert' function and I am calling the 'alert' function with the argument 46 00:03:56,400 --> 00:03:59,910 'Hi'. 'alert' needs to be called, 47 00:04:00,090 --> 00:04:02,460 otherwise it's just sitting there. 48 00:04:03,900 --> 00:04:08,880 Now the big reason to use function is that you can call them as many times as you want. 49 00:04:08,970 --> 00:04:19,079 Think about 'alert', imagine having to say every time "Hey, computer, create this 'popup' window and print whatever 50 00:04:19,079 --> 00:04:21,089 argument I put in" every time. 51 00:04:21,269 --> 00:04:27,540 I mean that would really suck. Isn't it nice, that we can just call 'alert' and that popup window pops up for 52 00:04:27,540 --> 00:04:29,770 us and everything's done for you? 53 00:04:29,780 --> 00:04:32,010 Well, that's pretty much what functions do. 54 00:04:32,010 --> 00:04:39,810 They make life easier by having actions, bundled up, so you only write them once and then you can just 55 00:04:39,810 --> 00:04:41,450 call it. 56 00:04:41,480 --> 00:04:43,480 OK. So let's get to the fun part. 57 00:04:43,490 --> 00:04:54,970 Let's create our own functions. So, if we go back to our document here, let's see right here. We have 2 58 00:04:54,970 --> 00:05:00,180 ways of creating functions and I'll show you the first way. 59 00:05:00,340 --> 00:05:01,980 Actually, I'm going to show you this one first. 60 00:05:02,200 --> 00:05:08,970 So, let's create our own function, using the first method, which is 'function declaration'. 61 00:05:09,310 --> 00:05:17,780 And we're going to use our 'script.js' here, that's linked to our HTML, that we did at the previous video. 62 00:05:17,930 --> 00:05:23,840 So, here I can say 'function sayHello()' 63 00:05:27,960 --> 00:05:30,510 is 'console.log("Hello")'. 64 00:05:35,380 --> 00:05:38,700 Again the syntax a little bit different, but you just have to remember it. 65 00:05:38,800 --> 00:05:41,850 I'm saying 'function' - is going to be called 'sayHello'. 66 00:05:42,070 --> 00:05:49,150 We have those brackets, that are very familiar to us. And then 'console.log("Hello");'. Let's see, what happens 67 00:05:49,150 --> 00:05:53,480 when I save. I refresh. 68 00:05:53,830 --> 00:05:54,860 Hmmm, nothing happens. 69 00:05:55,980 --> 00:05:56,920 Why is that? 70 00:05:57,240 --> 00:06:00,530 Well, we declared this function. 71 00:06:00,540 --> 00:06:09,430 But remember, what we did with 'alert'? Well, it exists, but we haven't run it. 72 00:06:09,480 --> 00:06:16,170 We have to call the function, so we have to say 'sayHello', like so. Now when I refresh. 73 00:06:16,740 --> 00:06:19,430 I get "Hello". 74 00:06:19,570 --> 00:06:25,610 So think of this with the variable. When I say 'var a equals 5', 75 00:06:25,720 --> 00:06:29,260 that's not going to do anything, until we actually get the 'a'. 76 00:06:29,560 --> 00:06:34,120 And that's when it prints '5'. 77 00:06:34,130 --> 00:06:36,500 OK. So that's one way. 78 00:06:36,510 --> 00:06:39,060 What's the second way of creating a function? 79 00:06:39,270 --> 00:06:45,150 The second way is called 'function expression'. 80 00:06:45,340 --> 00:06:47,900 And this goes like this. 81 00:06:48,130 --> 00:07:01,430 I can say 'var sayBye = function()' 'console.log("Bye");'. 82 00:07:02,300 --> 00:07:05,620 Again I'll save this and refresh. 83 00:07:05,810 --> 00:07:11,660 And again we only get 'Hello' because, well, again we have to call that function. 84 00:07:11,720 --> 00:07:20,560 So, I say 'sayBye', run it and refresh. "Hello", "Bye". Now 85 00:07:20,640 --> 00:07:30,040 one thing you may have noticed here, is that we're assigning this function to the 'sayBye' variable, but 86 00:07:30,940 --> 00:07:33,240 what is the name of the function? 87 00:07:33,250 --> 00:07:40,520 I mean here clearly function's name is 'sayHello', but here we're, we're just assigning to the variable. 88 00:07:40,520 --> 00:07:48,230 I mean, technically the function doesn't have a name and this is called an 'anonymous function'. 89 00:07:48,360 --> 00:07:54,480 We've assigned this function to 'sayBye', so we can reference it through 'sayBye', but otherwise we can't 90 00:07:54,480 --> 00:07:56,350 really access this function. 91 00:07:56,640 --> 00:07:59,880 Well, you'll see why that's important 92 00:07:59,940 --> 00:08:01,500 in later videos. 93 00:08:01,500 --> 00:08:06,770 But you could technically do this: and call this function 'byebye'. 94 00:08:13,110 --> 00:08:13,760 OK. 95 00:08:14,050 --> 00:08:20,560 So, now that we know, how to create functions, why do we need these arguments? 96 00:08:20,830 --> 00:08:23,740 Remember, why do we need stuff inside the brackets? 97 00:08:23,740 --> 00:08:26,660 I mean - these look useful enough, right? 98 00:08:27,630 --> 00:08:40,090 Well, let's try something. 'sing', let's do a function 'sing' and this 'sing' will have, will have 'console.log' 99 00:08:40,120 --> 00:08:46,220 and I'll say "AHHHHHHHHHHHH". That's, that's me, singing. 100 00:08:46,230 --> 00:08:51,550 And it also has 'console.log("TEEEEEEEEE")'. 101 00:08:52,030 --> 00:09:00,390 That's how I sing. Now, if I save this and refresh, make sure it still sings. Oh, I have to call it! 102 00:09:03,440 --> 00:09:04,920 Let's refresh. 103 00:09:05,040 --> 00:09:07,410 Beautiful song: AHHHHHHHHHHHH, TEEEEEEEEE. 104 00:09:07,680 --> 00:09:18,530 But now, every time I want to change to a different song, maybe I wanted to say 'laaa deeee daaa'. 105 00:09:18,660 --> 00:09:31,840 Well, I have to either delete this and change this to 'laaa deeee daaa' or I have to create a new one, calling 106 00:09:32,260 --> 00:09:33,640 'sing2' 107 00:09:36,310 --> 00:09:50,750 'console.log' and you can see over here, how annoying that is, that I'm typing the same thing over and over 108 00:09:51,020 --> 00:09:52,710 and just changing these things. 109 00:09:52,910 --> 00:10:00,090 And now I have to run 'sing2'. And I refresh, and phew, that was tiring! OK. 110 00:10:00,460 --> 00:10:07,600 I did all of this and now imagine, if we had thousands of songs, that we want to sing; we're 'Spotify' and 111 00:10:07,600 --> 00:10:10,330 we want to display all the song lyrics. 112 00:10:10,330 --> 00:10:13,210 I mean that's pretty-pretty tiring, right? 113 00:10:13,210 --> 00:10:18,680 And one of the rules with developers is this idea of "DRY: Do not repeat yourself". 114 00:10:18,730 --> 00:10:21,790 Ideally you want to make things as efficient as possible. 115 00:10:22,000 --> 00:10:34,820 And one thing you can do is - by adding arguments. So I can add something like 'song' and now - let me just 116 00:10:34,820 --> 00:10:35,970 delete this for now. 117 00:10:37,720 --> 00:10:46,670 In the 'console.log' I can just say 'song'. 118 00:10:46,820 --> 00:11:01,190 So now any time I want to change the song, I can say "Laaa deee daaa". 'sing("helllloooooo") 119 00:11:02,140 --> 00:11:02,990 Then "sing 120 00:11:05,330 --> 00:11:08,990 ("backstreets back alright") 121 00:11:11,770 --> 00:11:14,470 Now I save and refresh. 122 00:11:14,500 --> 00:11:23,060 And look at that! You see how many lines of code we just saved and how I can now use 'sing' any time I want, 123 00:11:23,330 --> 00:11:26,600 and I can customize it to what I want. 124 00:11:26,600 --> 00:11:28,050 Kind of like 'alert'. 125 00:11:28,130 --> 00:11:30,570 That's what arguments do. 126 00:11:30,830 --> 00:11:37,790 Arguments allow us to not repeat ourselves and make our functions what we call more extensible. 127 00:11:37,790 --> 00:11:40,530 They can be customized. 128 00:11:40,590 --> 00:11:44,860 Let's do one other thing to learn a fun thing about functions. 129 00:11:44,970 --> 00:11:57,450 We're going to delete this and try 'function multiply()'. And we'll give it 'a' and 'b', so it'll accept two 130 00:11:57,450 --> 00:12:01,330 arguments and we'll do 'a*b'. 131 00:12:01,710 --> 00:12:15,320 And now within 'a*b' we'll say 'multiply', and we'll call 'multiply(5, 10)'. Save and refresh. 132 00:12:15,460 --> 00:12:18,890 And now we should have 'multiply' available to us. 133 00:12:18,910 --> 00:12:24,570 You can see over here 'multiply(a, b)' that's 'b' exactly what we wrote. 134 00:12:24,600 --> 00:12:27,370 OK, so what happens if I do 'multiply' 135 00:12:29,630 --> 00:12:32,020 (5, 10)? 136 00:12:32,480 --> 00:12:33,410 What do you think I'll get? 137 00:12:33,560 --> 00:12:33,910 Let's see! 138 00:12:37,980 --> 00:12:39,770 Hmmm, that's really weird. 139 00:12:39,780 --> 00:12:42,340 Let's try that again with a different number. 140 00:12:42,370 --> 00:12:44,180 Still 'undefined'. 141 00:12:44,380 --> 00:12:47,530 Why is that? Well, this is called debugging. 142 00:12:47,530 --> 00:12:50,680 Let's see if we can figure out what's happening here. 143 00:12:50,680 --> 00:12:53,580 I'm going to do a 'console.log' here. 144 00:12:54,490 --> 00:12:59,050 And I'm going to log out 'a' and 'b' to make sure that this function's actually running. 145 00:12:59,210 --> 00:13:11,600 So I'm going to save and refresh. OK. 'console.log', 'a' and 'b' and I just run the function again. 146 00:13:11,660 --> 00:13:17,610 'console.log'. OK. So it looks like it's running, but then I'm getting 'undefined' over here. 147 00:13:17,770 --> 00:13:23,440 Well, I can show you this in a diagram. 148 00:13:23,440 --> 00:13:27,270 So, a function is an 'input'. 149 00:13:27,330 --> 00:13:32,270 We give it some sort of an 'input', maybe sometimes it's empty, so that's whatever's in the bracket. 150 00:13:32,460 --> 00:13:34,900 In our case it's 'a' and 'b'. 151 00:13:35,010 --> 00:13:42,790 So those are numbers, so '5' and '10'. And then the function does whatever we tell it to do. 152 00:13:42,790 --> 00:13:51,550 In our case it was to 'multiply 5 and 10'. And then we get an 'output', but we're not getting that 'output'. 153 00:13:51,550 --> 00:13:52,280 Why is that? 154 00:13:52,350 --> 00:13:56,270 Well, because a function works like this. 155 00:13:56,650 --> 00:14:01,450 And don't worry, I've just added a bunch of arrows, but I'll go through everything and explain it to you. 156 00:14:01,450 --> 00:14:03,400 The 'input' is receiving '5' and '10'. 157 00:14:03,400 --> 00:14:11,950 The function does some stuff, and up to this point we've only done 'console.log', and the way 'console.log' 158 00:14:11,950 --> 00:14:18,870 works is, the function is saying: 'Just log it to the console in the browser'. 159 00:14:19,100 --> 00:14:24,400 But we've never done it where we've returned a 'value'. 160 00:14:24,470 --> 00:14:25,820 Let me show you what I mean. 161 00:14:26,600 --> 00:14:29,300 When we don't return something, we get 'undefined'. 162 00:14:29,330 --> 00:14:32,240 When we return something, we get the 'value'. 163 00:14:32,240 --> 00:14:37,090 So let's see over here if we can explain this. 164 00:14:37,110 --> 00:14:47,410 So, here whenever I am saying 'multiply (10 ,5)', and I'm going to remove the 'console.log' just so it doesn't confuse 165 00:14:47,410 --> 00:14:50,400 us, save and refresh... 166 00:14:50,770 --> 00:14:51,820 I get 'undefined'. 167 00:14:52,000 --> 00:14:56,710 That is because as you see in this diagram we're not returning anything. 168 00:14:56,710 --> 00:15:04,330 So, in JavaScript the way you return things is - you have to put in 'return' inside of a function. 169 00:15:04,690 --> 00:15:12,400 So, now it's going to 'return a * b' and you see, that it's a - it's a special word in JavaScript - it 170 00:15:12,400 --> 00:15:13,740 highlighted in red. 171 00:15:14,020 --> 00:15:20,310 Well, now it's saying 'Yep, we're going to return the value'. 172 00:15:20,370 --> 00:15:28,320 So, even if we added 'console.log'. You'll do 'console.log' and then ask "Hey, do I have a 'return'?". 173 00:15:28,470 --> 00:15:31,160 If I do, I'm going to send it a value. 174 00:15:32,170 --> 00:15:33,520 Hopefully, that's not too confusing. 175 00:15:33,520 --> 00:15:35,170 Let's see if it works. 176 00:15:35,930 --> 00:15:37,980 I'm going to save and refresh. 177 00:15:38,240 --> 00:15:47,700 And now if I do 'multiply (5, 10)', I get '50'. 178 00:15:47,840 --> 00:15:56,860 Yay! We got our function working and that is a very important key concept, that we need to remember 179 00:15:56,860 --> 00:16:01,010 is that we need to return something from a function. 180 00:16:01,030 --> 00:16:02,870 I mean we don't have to. 181 00:16:02,980 --> 00:16:07,990 But ideally we do, so we don't get these cases, where we just have 'undefined' and we don't know what the 182 00:16:07,990 --> 00:16:08,680 function does. 183 00:16:08,680 --> 00:16:14,830 It's kind of like a 'black box', that does something and we might get a 'console.log', or not but we don't 184 00:16:14,830 --> 00:16:16,410 know what's happening inside. 185 00:16:16,410 --> 00:16:22,620 It's nice to have a 'return' to make sure that the function acts the way we expect it to. 186 00:16:22,650 --> 00:16:24,540 Ok, what if we do something like this? 187 00:16:24,540 --> 00:16:33,550 What if I do 'return a', and I forgot a semicolon here, and 'return b'. What do you think will happen? Let's 188 00:16:33,550 --> 00:16:37,930 refresh and run this. 189 00:16:37,960 --> 00:16:38,540 OK. 190 00:16:38,830 --> 00:16:41,870 What if I change the order and I put 'a' first? 191 00:16:41,960 --> 00:16:43,080 Let's try that again. 192 00:16:44,960 --> 00:16:54,550 I get '5' and 'return' is the final way to end a function if that makes sense. So, as soon as you say 193 00:16:54,550 --> 00:16:57,770 'return' in a function, the program exits. 194 00:16:57,820 --> 00:17:04,240 So, to go through this I say 'multiply (5, 10)'. It goes to the function, it says: "Yep, I have the function 195 00:17:04,240 --> 00:17:10,690 'multiply'. I'm going to put 'a' as '5' and '10' as 'b'". 196 00:17:10,839 --> 00:17:20,540 And now it goes into the function and says: 'return 5', which is 'a'. So it returns that and exits the function. 197 00:17:20,950 --> 00:17:23,290 So now these two lines aren't being run at all. 198 00:17:23,290 --> 00:17:30,090 The program simply reads this, goes to here, reads the first line of the function and then exits. 199 00:17:30,100 --> 00:17:37,630 So, in a function you should have one 'return' statement, or is that right? 200 00:17:38,500 --> 00:17:41,910 Let's see a case where that might not be correct. 201 00:17:41,920 --> 00:17:43,750 Let's add an 'if' statement to this. 202 00:17:44,080 --> 00:17:53,330 Let's say that we want to do 'multiply', but we're also kind of lazy and we don't want to be too hard with 203 00:17:53,330 --> 00:17:54,040 the computer. 204 00:17:54,140 --> 00:18:05,420 So let's say we want to say that, 'if' - we remember the 'if statement'. "if 'a' is greater than '10'" or "if 'b' is 205 00:18:05,420 --> 00:18:07,430 greater than '10'". 206 00:18:10,170 --> 00:18:18,430 We can say 'return "that's too hard";'. 207 00:18:18,710 --> 00:18:19,290 Otherwise [else] 208 00:18:25,850 --> 00:18:33,380 we'll return 'a * b'. Let's see what happens here. 209 00:18:34,890 --> 00:18:39,050 I'm going to save and refresh. Let's do 'multiply (5,4)'. 210 00:18:43,400 --> 00:18:46,220 I get '20'. 211 00:18:46,270 --> 00:18:49,680 What if we do '5' and '40'? I get 212 00:18:49,690 --> 00:19:01,180 "that's too hard", because now it's reading the function '5' and '10', and it's saying: "Hmmm, 'b', which is '40' is higher 213 00:19:01,180 --> 00:19:02,440 than '10'". 214 00:19:02,470 --> 00:19:06,560 So, according to the 'if statement' I'm going to go "that's too hard". 215 00:19:06,670 --> 00:19:19,480 And because a 'return' exits the function, it never gets to this, even if I do 'return a * b', you'll never 216 00:19:19,480 --> 00:19:24,490 get there, because the 'return' exits the function. Just to double check, 217 00:19:24,490 --> 00:19:28,960 let's do that: let's do '5*40'. 218 00:19:28,970 --> 00:19:34,750 And it never gets to any of these lines, because as soon as this sees a 'return', it exits the function. 219 00:19:35,790 --> 00:19:37,320 I know it's a lot. 220 00:19:37,320 --> 00:19:41,980 And we'll get to why these things are important in the next couple of videos. 221 00:19:42,210 --> 00:19:50,540 But I wanted to also show you that you can have inner functions. So in JavaScript functions are 'variables'. 222 00:19:50,880 --> 00:19:54,120 And what that means is, that we were able to assign 223 00:19:56,880 --> 00:19:59,990 functions like this. Right? 224 00:20:00,200 --> 00:20:02,960 And if we did something like this, 225 00:20:03,080 --> 00:20:09,640 well, we can call 'a' in the same way that we did and we just assigned function as a variable. 226 00:20:09,680 --> 00:20:15,030 So technically we could do something like this. 227 00:20:15,050 --> 00:20:22,830 So let's have 'multiply' - Let's go back to the way we had it. We'll leave 'multiply' the way it is in the 228 00:20:22,830 --> 00:20:23,580 simple form. 229 00:20:27,330 --> 00:20:29,640 And we can actually 230 00:20:32,140 --> 00:20:38,190 say 'alert(multiply)'. 231 00:20:38,650 --> 00:20:43,900 And then here we'll do '3' and '4'. And I know that's a lot of brackets. 232 00:20:43,900 --> 00:20:45,620 Don't worry we'll go through it. 233 00:20:45,760 --> 00:20:49,490 But, let's just save this and refresh and see what happens. 234 00:20:49,570 --> 00:20:58,150 I get '12'. Because what's happening is: We're starting with the inner function and we're saying: "Hey, we 235 00:20:58,150 --> 00:20:59,330 want to alert something!". 236 00:20:59,470 --> 00:21:00,630 "What do you want to alert?" 237 00:21:00,640 --> 00:21:03,610 "Well, we want to 'multiply'" 238 00:21:03,610 --> 00:21:06,330 "We want to call this function and give 'a' it '3' and '4'". 239 00:21:06,400 --> 00:21:14,560 So it goes to 'multiply' and it says: "Yep, we'll assign 'a' and 'b' to '3' and '4', and I want to return 'a' and 'b'. 240 00:21:14,560 --> 00:21:24,010 So now 'multiply' gets changed to '12' and then we 'alert'. 241 00:21:24,020 --> 00:21:33,580 So, you see that now, instead of having something like 'total', 'multiply(4,5)' and then putting 'total' 242 00:21:33,590 --> 00:21:37,420 here, we can just assign 'multiply' into here. 243 00:21:40,370 --> 00:21:41,620 Whew! that was, that was a lot! 244 00:21:41,640 --> 00:21:44,850 But I want to show you that we've - we've tackled, 245 00:21:44,880 --> 00:21:51,000 I think, the hardest topic in JavaScript, which is functions. And you've also covered the 'return', which 246 00:21:51,000 --> 00:21:53,040 is very very good. 247 00:21:53,050 --> 00:21:59,140 The one other thing I want to show you is that a lot of people get confused with the terminology and 248 00:21:59,260 --> 00:22:02,340 I don't think it's as important but I just want to clarify it. 249 00:22:02,390 --> 00:22:11,370 There is the concept of 'parameters' and 'arguments'. 250 00:22:11,400 --> 00:22:18,520 Now 'parameters' and 'arguments' kind of are very similar but just slightly different. 251 00:22:18,520 --> 00:22:22,420 So 'arguments' as we've said, are '4' and '5'. 252 00:22:22,480 --> 00:22:27,640 So functions can have 'arguments' and they get called with 'arguments'. 253 00:22:28,060 --> 00:22:31,330 'Parameters' are what 'a' and 'b' is. 254 00:22:31,330 --> 00:22:36,290 So 'multiply' has two 'parameters' of 'a' and 'b'. 255 00:22:36,420 --> 00:22:38,210 I know that's a little bit confusing. 256 00:22:38,210 --> 00:22:40,010 You can read up on it a little bit more. 257 00:22:40,010 --> 00:22:46,860 I don't think it's important to really know the difference, but just so whenever you're reading articles 258 00:22:46,860 --> 00:22:52,550 or learning, maybe through YouTube, that you'll hear these words almost interchangeably. 259 00:22:52,590 --> 00:22:56,710 They pretty much mean the same thing, just a little bit slight difference in them. 260 00:22:58,460 --> 00:23:00,290 All right! 261 00:23:00,910 --> 00:23:03,690 I know, I know I've thrown a lot of terminology at you! 262 00:23:03,730 --> 00:23:10,780 But after repeating it a few times it will make sense, so stay strong. But that's it for functions. 263 00:23:11,080 --> 00:23:13,580 It's time for you to try some exercises. 264 00:23:13,600 --> 00:23:15,420 Rewatch this video if you need to. 265 00:23:15,430 --> 00:23:21,370 You really want to make sure you understand functions, since it will be the core of JavaScript. 266 00:23:21,370 --> 00:23:28,360 Just remember, what we're doing with functions is, we are creating new words in the language, in the JavaScript 267 00:23:28,360 --> 00:23:34,510 language. So we can create 'variables' or we can create 'functions' to add vocabulary to the language and 268 00:23:34,750 --> 00:23:37,370 up to this point that's all we've been doing. 269 00:23:37,390 --> 00:23:44,950 We got this JavaScript that had a few words, that we can use, and we've added new ones like 'multiply' and 270 00:23:45,370 --> 00:23:48,760 'total' in order to make it more useful to us. 271 00:23:49,000 --> 00:23:51,020 And that's what programming is. 272 00:23:51,210 --> 00:23:53,110 I'll see you in the next one. Bye-bye