All right.
We come back in this video.
Let's get started with functions.
But before we get into that, we need to know the syntax of a function where we have couple of ways
of declaring or creating a function.
The first one that you talk about is called function declaration.
So as always, we need to bring in our function keyword.
This one is from JavaScript.
You bring in your function keyword.
Okay?
And then the next one here is going to be the name of your function, function name.
And then a function would take in what is called parameters.
Then we have our cases here, and then our code to be executed lies in this.
So let's let me show you with code to better understand what a function is all about.
As usual, because we are starting a new concept.
I have created a new project or folder for it and I have name it as functions that is functions over
here and inside I have one HTML and then with the head each one functions over there and have required
my JavaScript inside that.
So let me close this one and now let's start with function that is JavaScript here.
So we have couple of ways of defining a function.
So come here says ways of declaring or creating a function.
Ways of creating.
A function.
And we have two ways.
One is using the function.
Declaration.
And then the other one is called function.
Expression.
So.
In this video, let's have a look at a simple function that add two numbers together for now, not add,
let's say, a function to say or to greet somebody say let's say hello.
You are welcome.
And we're going to display that one inside the console.
So let's say create a function to say hello.
JS That so as you remember from here to create that we bring in our function keyword.
So here we go, function keyword here.
The next one is the name of my function as a variable name.
So the name of a function must depict what it does.
So we say say hello, that our function name is that I'm using common cases.
So depending how you want to name your variables, as we discussed before, that is my function name
and my.
Brackets here.
So then I bring my body here as that, and then my carry braces.
That is a function.
Again, this is what you call function declaration.
So let me.
Bring it here.
As call function decoration.
This what you call function decoration.
So inside the codebases is where your code will be here.
So a function to say hello.
So in the body.
That's where I'm going with our logic.
So we just want to console, log, simple message, console, log and say.
Hello.
Work on two functions.
That is it.
So I have created my first function.
So how can I use this particular function?
And that is what you call function invocation.
Meaning calling a function is called function invocation.
So as soon as you create a function well, we have saved the function called say hello in memory of
JavaScript.
So anywhere I want to use this message.
If I call my function, I will say hello.
Welcome to function.
So if I check my calls, the function or what is function is doing that just display this message to
the console.
That's a basic function.
So to be able to view.
Let's open the console.
And now we see that well, this is where.
Right.
Nothing has been shown here because we have not called the function.
So after we create a function, we need to call it or invoke.
So here is create a function here.
And then if you don't call it well, the function will not do anything.
So down here, let's say, calling a function.
Or is our system as function invocation won't invoke the function?
How do we invoke a function?
So to be able to know that.
Certain variable is a function.
Let me show you the clue.
So here to call the function, you bring in your function name.
That is, say hello.
If I do this one, I save it.
So nothing has been shown here.
So to call a function, you need to bring your.
Brackets like that.
Now, with this one, if I save this one.
Now, if you see that, I have.
Hello.
Welcome to function.
Because I have called a function.
Meaning?
I have my square bracket here.
Meaning calling the function.
So anything that we see a variable with this square bracket around it, it tells you it's a function.
So you can see that even console dot now no console dot log.
How will we see about this?
This is a function because look at the curves, the square bracket here we have the square bracket here,
which means it's a function.
So that is pretty much it about how we can create a function, the first one.
Now let's move step by step.
First of all, we knew how to create a function and then we knew how to call a function.
That's the first step about function declaration.
What about function expression?
Where's my function expression?
Yeah.
Here is step number two.
How can we create function expression?
So here is my function.
Expression, perfect.
So how can we create that kind of function function?
So for function expression, we assign a function to a variable.
So the name of this function.
Let me comment about this one or let me leave it.
So this function is going to also, I mean, displace a message and say, yes, I mean, good morning.
Yes.
Just grid a function to grid.
Okay.
So here you bring in your name calling.
So let me show you with this picture here.
So we call this one function expression.
We have our keyword here led and then we have a variable name equal to the function keyword and then
our square bracket and a function body as compared to function declaration we don't have let's we don't
have equal to that is function declaration and this function expression.
So here a function going to be grading I'm going to do somebody and then assign to equal to the name
of my function and my square bracket and my carry basis.
So in here I just console.log something and say good morning.
Perfect.
So let me comment this one out because I don't want to call this function.
So if I save it now, my console is empty because I haven't called this function.
So the way we call function declaration, it is same as calling function expression.
So here I would just bring in my greeting and then call my function.
I start and now I have.
Good morning.
So before we end this video, just have a look.
The two ways of creating a function function, the creation and then function expression.
And after creating, we need to call the function.
These are the two things you need to take note in this particular video.
So let me give you an exercise.
Okay.
So exercise is like this one.
Create a function to greet your mom.
Can say Hello Mom.
Good morning or Hello, Mom, how are you?
Okay.
So create.
Create a function.
To greet Mom.
That is it to any message you want you to get your mom?
Why not go ahead and do it?
So here you can give your function a name the way you want it.
But a name must be descriptive and then just console.log.
I mean, Mom, how are you?
Good morning.
I miss you.
Something like that.
So let's see how you're going to do this one.
In this video.
And in this video, you solve it and talk about another key concept when you come to function.
The next video.