Welcome back and today's lecture, we will not learn anything new, but we will repeat some of the JavaScript
terminology that we used so far in the lectures.
Now, first things, let's start with functions now create electorate that just file Ilinka here if
you're following me.
OK, now, if you read somewhere, declare.
They clear a function, right?
So what does this mean, right, let's write a function here, function first.
First function, and that's pretty much it.
Now every function starts with a function keyword.
Then we named the function in these brackets means, OK, we have a function in inside here.
They can take on arguments.
These curly brackets, on the other hand, means the body of the function.
Right.
And declaring a function means creating function and naming that function.
That means declaration of function.
OK, now let's talk about the function arguments.
Now we can have one, two or more argument or we don't need arguments at all like this function here.
So let's create another function called second function.
And inside this function, I will have name and age.
So the arguments are spaced between by and separated by comma.
Right now, when we are calling this function, we need to call this function together with the arguments.
And that is pretty much the third step.
And it's called call or invoke the function.
Right.
So when we do that, we say second function, oops, second function.
And we need to use the parentheses.
This means call and execute this function.
But inside we need to put the parameters or sorry, the arguments.
So let's put Trig in twenty three.
That is pretty much it.
Now, if you go back to a browser, you're not going to see anything.
Why?
Because we call the function, but there is nothing in the function and that is called body of the function.
Very good.
Now, the body of the function, we can have multiple lines and let's just comment this one out based
here.
Or actually, I'm going to use I'm going to create a new one, right.
Third function that will take name and age and we're going to call that third function right below here.
And let's put here Andy and twenty nine.
OK, so the body of a function goes multiple lines of code.
Here is our logic.
So I'm just going to consulate like the name and I'm going to concatenate and.
He is.
And age here, nice.
So now you should be able to see Andy is doesn't we don't need this one.
Andy is twenty nine years old, right.
We can concatenate this one years.
All very good.
So this is how you declare a function first, then you choose the arguments.
If you want arguments, then you call or invoke the function like this.
And the third is the body of the function.
The body of the function can have multiple things based on our logic.
Very good.
Now we do have a function expression.
Let's talk about that a little bit.
And what are we having a function expression?
Well, we need to create a variable called function X sorry expression and then the function.
Very good.
Now here.
What is the difference between this and this?
Well, this function doesn't have a name and it's called anonymous function, but it can have names
and I'm not going to do it here because that is not something that you're going to see anywhere.
Right.
So how are we going to call this function to call or invoke function expression?
Right.
So how are we going to do this?
So we're going to invoke by the variable name.
So everything that this function will return or do is say let's return five or return.
And Sam here, I'm going to say Sam.
Right.
So this function will return something and it will store here.
So when we call the function, for example, for name.
Function expression.
That's it, because we don't take any arguments here, we're not going to we're not going to send arguments
there right now in the name, I will get whatever it's stored, whatever is returned from this function.
So if I do a lot, just the name I should have said.
Right.
Very good.
That is pretty much it.
The third thing is.
Expression, let me just talk about this one.
Let me just read here.
Oops, assign a variable date up to a variable.
So how we do this?
Well, we do with equal sign, for example, where our first name, it will be John.
So this is how we are assigned the variable first name that to hold data, John.
Right.
So this is how we are signing a data to a variable.
Very good.
Now, what is the expression now?
The expression means something that returns and produce a value and always needs to have a semicolon
at the end.
Right.
This is called an expression.
OK, now let's talk about methods.
Methods.
Our functions inside.
An object.
Very good.
Now, let me write an object real quick here.
So how we write an object with the curly brackets.
So we have name Rick H.
Thirty three year birthday.
This is going to be the function.
Now, how we call the function inside an object.
So they're called methods.
Let's put here nineteen eighty seven just like that.
Very good.
Now the last part, how the object access their methods.
Object Method's.
Very good.
So object that year of birth.
Very good, but we need to specify this curly brackets because not curly brackets these brackets, because
this means that we are just calling a function.
Right.
Nice.
Save it.
Here it is.
The function will produce that.
So that is pretty much the last thing that I want to mention is the arrays, how we declaring an empty
array.
Array and war are my array, and this will be an empty array.
And the arrays have their own indexes.
Let's put more secondary.
And let's say here, Jimmy.
Tommy, very good.
So if we want to access the first item of disarray, their index based, so these are called items inside
their space with comma in their index base.
So arrays are always index based.
So if I want to access any of the items there, then I need to know the index.
But what is good, they always start from zero.
And so what we can do so we can cancel out these secondary.
Second array and in these square brackets, we need to say zero if I want to access Jimmy.
Very good.
Now I have Jimmy, if I want to access Tommy, it will be number one.
Also, what I haven't shown you, if you want to know the length of the area.
You can say second area that length and it should give you the result of two.
Why?
Because we do have council that log secondary.
We do have array of length through here it is.
We have two items inside the Leontes, too.
That's why I can use this method here straight away on the arrays.
So that's pretty much it for this lecture.
I hope you enjoy it.
You need to get used to this terminology and because you will use it pretty much everywhere.
So, Susan.