1 00:00:00,790 --> 00:00:07,000 Welcome back and today's lecture, we will not learn anything new, but we will repeat some of the JavaScript 2 00:00:07,180 --> 00:00:10,990 terminology that we used so far in the lectures. 3 00:00:11,200 --> 00:00:19,570 Now, first things, let's start with functions now create electorate that just file Ilinka here if 4 00:00:19,570 --> 00:00:20,530 you're following me. 5 00:00:20,710 --> 00:00:24,970 OK, now, if you read somewhere, declare. 6 00:00:26,920 --> 00:00:29,470 They clear a function, right? 7 00:00:29,500 --> 00:00:33,640 So what does this mean, right, let's write a function here, function first. 8 00:00:36,200 --> 00:00:39,420 First function, and that's pretty much it. 9 00:00:39,890 --> 00:00:42,530 Now every function starts with a function keyword. 10 00:00:42,920 --> 00:00:49,370 Then we named the function in these brackets means, OK, we have a function in inside here. 11 00:00:49,370 --> 00:00:50,750 They can take on arguments. 12 00:00:51,110 --> 00:00:54,440 These curly brackets, on the other hand, means the body of the function. 13 00:00:54,710 --> 00:00:55,100 Right. 14 00:00:55,460 --> 00:01:00,030 And declaring a function means creating function and naming that function. 15 00:01:00,050 --> 00:01:02,630 That means declaration of function. 16 00:01:02,970 --> 00:01:07,720 OK, now let's talk about the function arguments. 17 00:01:08,300 --> 00:01:15,020 Now we can have one, two or more argument or we don't need arguments at all like this function here. 18 00:01:15,290 --> 00:01:19,550 So let's create another function called second function. 19 00:01:19,550 --> 00:01:24,800 And inside this function, I will have name and age. 20 00:01:25,130 --> 00:01:30,500 So the arguments are spaced between by and separated by comma. 21 00:01:30,740 --> 00:01:36,290 Right now, when we are calling this function, we need to call this function together with the arguments. 22 00:01:36,650 --> 00:01:39,500 And that is pretty much the third step. 23 00:01:39,500 --> 00:01:46,420 And it's called call or invoke the function. 24 00:01:46,580 --> 00:01:46,950 Right. 25 00:01:47,150 --> 00:01:54,950 So when we do that, we say second function, oops, second function. 26 00:01:55,460 --> 00:01:57,440 And we need to use the parentheses. 27 00:01:57,440 --> 00:02:00,050 This means call and execute this function. 28 00:02:00,320 --> 00:02:03,790 But inside we need to put the parameters or sorry, the arguments. 29 00:02:04,040 --> 00:02:08,090 So let's put Trig in twenty three. 30 00:02:08,890 --> 00:02:09,980 That is pretty much it. 31 00:02:10,180 --> 00:02:12,770 Now, if you go back to a browser, you're not going to see anything. 32 00:02:12,800 --> 00:02:13,180 Why? 33 00:02:13,460 --> 00:02:21,820 Because we call the function, but there is nothing in the function and that is called body of the function. 34 00:02:24,910 --> 00:02:25,540 Very good. 35 00:02:25,600 --> 00:02:34,640 Now, the body of the function, we can have multiple lines and let's just comment this one out based 36 00:02:34,690 --> 00:02:35,140 here. 37 00:02:36,330 --> 00:02:39,720 Or actually, I'm going to use I'm going to create a new one, right. 38 00:02:42,270 --> 00:02:48,720 Third function that will take name and age and we're going to call that third function right below here. 39 00:02:49,050 --> 00:02:54,420 And let's put here Andy and twenty nine. 40 00:02:54,730 --> 00:02:59,680 OK, so the body of a function goes multiple lines of code. 41 00:02:59,820 --> 00:03:01,070 Here is our logic. 42 00:03:01,320 --> 00:03:08,790 So I'm just going to consulate like the name and I'm going to concatenate and. 43 00:03:10,960 --> 00:03:11,860 He is. 44 00:03:13,990 --> 00:03:15,770 And age here, nice. 45 00:03:16,330 --> 00:03:21,780 So now you should be able to see Andy is doesn't we don't need this one. 46 00:03:21,790 --> 00:03:25,600 Andy is twenty nine years old, right. 47 00:03:25,660 --> 00:03:28,600 We can concatenate this one years. 48 00:03:31,050 --> 00:03:32,380 All very good. 49 00:03:33,060 --> 00:03:39,090 So this is how you declare a function first, then you choose the arguments. 50 00:03:39,090 --> 00:03:43,140 If you want arguments, then you call or invoke the function like this. 51 00:03:43,710 --> 00:03:45,930 And the third is the body of the function. 52 00:03:45,930 --> 00:03:48,940 The body of the function can have multiple things based on our logic. 53 00:03:49,350 --> 00:03:49,860 Very good. 54 00:03:50,310 --> 00:03:53,670 Now we do have a function expression. 55 00:03:54,300 --> 00:03:55,860 Let's talk about that a little bit. 56 00:03:59,040 --> 00:04:01,030 And what are we having a function expression? 57 00:04:01,050 --> 00:04:10,540 Well, we need to create a variable called function X sorry expression and then the function. 58 00:04:11,880 --> 00:04:12,450 Very good. 59 00:04:12,720 --> 00:04:13,710 Now here. 60 00:04:16,240 --> 00:04:18,940 What is the difference between this and this? 61 00:04:18,970 --> 00:04:24,370 Well, this function doesn't have a name and it's called anonymous function, but it can have names 62 00:04:24,670 --> 00:04:29,820 and I'm not going to do it here because that is not something that you're going to see anywhere. 63 00:04:30,220 --> 00:04:30,590 Right. 64 00:04:30,760 --> 00:04:39,500 So how are we going to call this function to call or invoke function expression? 65 00:04:39,610 --> 00:04:39,970 Right. 66 00:04:40,330 --> 00:04:41,320 So how are we going to do this? 67 00:04:41,890 --> 00:04:44,350 So we're going to invoke by the variable name. 68 00:04:44,710 --> 00:04:52,090 So everything that this function will return or do is say let's return five or return. 69 00:04:53,110 --> 00:04:55,520 And Sam here, I'm going to say Sam. 70 00:04:55,690 --> 00:04:56,050 Right. 71 00:04:56,590 --> 00:04:59,030 So this function will return something and it will store here. 72 00:04:59,320 --> 00:05:03,280 So when we call the function, for example, for name. 73 00:05:06,200 --> 00:05:07,400 Function expression. 74 00:05:08,470 --> 00:05:14,770 That's it, because we don't take any arguments here, we're not going to we're not going to send arguments 75 00:05:14,770 --> 00:05:21,710 there right now in the name, I will get whatever it's stored, whatever is returned from this function. 76 00:05:21,880 --> 00:05:27,560 So if I do a lot, just the name I should have said. 77 00:05:28,120 --> 00:05:28,400 Right. 78 00:05:28,930 --> 00:05:29,530 Very good. 79 00:05:30,040 --> 00:05:30,980 That is pretty much it. 80 00:05:31,420 --> 00:05:32,740 The third thing is. 81 00:05:34,170 --> 00:05:38,520 Expression, let me just talk about this one. 82 00:05:38,550 --> 00:05:39,810 Let me just read here. 83 00:05:41,160 --> 00:05:48,450 Oops, assign a variable date up to a variable. 84 00:05:51,210 --> 00:05:52,110 So how we do this? 85 00:05:52,800 --> 00:06:03,210 Well, we do with equal sign, for example, where our first name, it will be John. 86 00:06:05,510 --> 00:06:13,320 So this is how we are assigned the variable first name that to hold data, John. 87 00:06:13,490 --> 00:06:13,860 Right. 88 00:06:14,060 --> 00:06:16,470 So this is how we are signing a data to a variable. 89 00:06:16,850 --> 00:06:18,020 Very good. 90 00:06:18,590 --> 00:06:22,160 Now, what is the expression now? 91 00:06:22,160 --> 00:06:28,820 The expression means something that returns and produce a value and always needs to have a semicolon 92 00:06:28,820 --> 00:06:29,500 at the end. 93 00:06:30,080 --> 00:06:30,490 Right. 94 00:06:30,740 --> 00:06:32,300 This is called an expression. 95 00:06:32,750 --> 00:06:35,840 OK, now let's talk about methods. 96 00:06:36,470 --> 00:06:37,100 Methods. 97 00:06:39,840 --> 00:06:42,960 Our functions inside. 98 00:06:45,740 --> 00:06:46,440 An object. 99 00:06:47,390 --> 00:06:47,930 Very good. 100 00:06:48,260 --> 00:06:51,090 Now, let me write an object real quick here. 101 00:06:51,440 --> 00:06:53,770 So how we write an object with the curly brackets. 102 00:06:54,110 --> 00:06:58,460 So we have name Rick H. 103 00:06:59,570 --> 00:07:03,400 Thirty three year birthday. 104 00:07:04,110 --> 00:07:06,120 This is going to be the function. 105 00:07:06,140 --> 00:07:09,210 Now, how we call the function inside an object. 106 00:07:09,240 --> 00:07:10,550 So they're called methods. 107 00:07:14,000 --> 00:07:18,440 Let's put here nineteen eighty seven just like that. 108 00:07:19,400 --> 00:07:19,970 Very good. 109 00:07:20,660 --> 00:07:24,410 Now the last part, how the object access their methods. 110 00:07:30,920 --> 00:07:32,060 Object Method's. 111 00:07:33,830 --> 00:07:34,580 Very good. 112 00:07:34,610 --> 00:07:38,740 So object that year of birth. 113 00:07:39,050 --> 00:07:46,070 Very good, but we need to specify this curly brackets because not curly brackets these brackets, because 114 00:07:46,070 --> 00:07:48,490 this means that we are just calling a function. 115 00:07:48,500 --> 00:07:48,750 Right. 116 00:07:49,370 --> 00:07:49,940 Nice. 117 00:07:49,940 --> 00:07:50,490 Save it. 118 00:07:51,290 --> 00:07:51,950 Here it is. 119 00:07:52,250 --> 00:07:53,970 The function will produce that. 120 00:07:54,230 --> 00:07:59,690 So that is pretty much the last thing that I want to mention is the arrays, how we declaring an empty 121 00:07:59,690 --> 00:08:00,110 array. 122 00:08:04,390 --> 00:08:12,760 Array and war are my array, and this will be an empty array. 123 00:08:13,550 --> 00:08:16,610 And the arrays have their own indexes. 124 00:08:17,060 --> 00:08:20,090 Let's put more secondary. 125 00:08:22,130 --> 00:08:25,700 And let's say here, Jimmy. 126 00:08:28,870 --> 00:08:30,530 Tommy, very good. 127 00:08:30,760 --> 00:08:39,070 So if we want to access the first item of disarray, their index based, so these are called items inside 128 00:08:39,100 --> 00:08:42,710 their space with comma in their index base. 129 00:08:42,710 --> 00:08:44,610 So arrays are always index based. 130 00:08:44,640 --> 00:08:49,090 So if I want to access any of the items there, then I need to know the index. 131 00:08:49,100 --> 00:08:51,440 But what is good, they always start from zero. 132 00:08:52,240 --> 00:08:56,290 And so what we can do so we can cancel out these secondary. 133 00:08:59,040 --> 00:09:07,630 Second array and in these square brackets, we need to say zero if I want to access Jimmy. 134 00:09:08,010 --> 00:09:08,670 Very good. 135 00:09:09,180 --> 00:09:13,530 Now I have Jimmy, if I want to access Tommy, it will be number one. 136 00:09:15,090 --> 00:09:18,790 Also, what I haven't shown you, if you want to know the length of the area. 137 00:09:18,840 --> 00:09:24,930 You can say second area that length and it should give you the result of two. 138 00:09:25,050 --> 00:09:25,530 Why? 139 00:09:25,740 --> 00:09:31,410 Because we do have council that log secondary. 140 00:09:31,740 --> 00:09:34,580 We do have array of length through here it is. 141 00:09:34,590 --> 00:09:36,920 We have two items inside the Leontes, too. 142 00:09:36,960 --> 00:09:40,920 That's why I can use this method here straight away on the arrays. 143 00:09:41,130 --> 00:09:42,970 So that's pretty much it for this lecture. 144 00:09:43,080 --> 00:09:44,000 I hope you enjoy it. 145 00:09:44,310 --> 00:09:51,280 You need to get used to this terminology and because you will use it pretty much everywhere. 146 00:09:51,390 --> 00:09:52,380 So, Susan.