1
00:00:00,950 --> 00:00:01,819
All right.

2
00:00:01,819 --> 00:00:04,730
We come back in this video.

3
00:00:04,820 --> 00:00:07,510
Let's get started with functions.

4
00:00:07,520 --> 00:00:14,540
But before we get into that, we need to know the syntax of a function where we have couple of ways

5
00:00:14,540 --> 00:00:17,390
of declaring or creating a function.

6
00:00:17,630 --> 00:00:22,670
The first one that you talk about is called function declaration.

7
00:00:23,370 --> 00:00:30,750
So as always, we need to bring in our function keyword.

8
00:00:30,750 --> 00:00:33,310
This one is from JavaScript.

9
00:00:33,330 --> 00:00:36,750
You bring in your function keyword.

10
00:00:37,260 --> 00:00:37,580
Okay?

11
00:00:37,860 --> 00:00:43,680
And then the next one here is going to be the name of your function, function name.

12
00:00:44,130 --> 00:00:47,640
And then a function would take in what is called parameters.

13
00:00:47,690 --> 00:00:53,490
Then we have our cases here, and then our code to be executed lies in this.

14
00:00:53,910 --> 00:00:59,340
So let's let me show you with code to better understand what a function is all about.

15
00:00:59,580 --> 00:01:03,540
As usual, because we are starting a new concept.

16
00:01:03,540 --> 00:01:13,620
I have created a new project or folder for it and I have name it as functions that is functions over

17
00:01:13,620 --> 00:01:23,490
here and inside I have one HTML and then with the head each one functions over there and have required

18
00:01:23,490 --> 00:01:25,170
my JavaScript inside that.

19
00:01:25,170 --> 00:01:32,550
So let me close this one and now let's start with function that is JavaScript here.

20
00:01:33,090 --> 00:01:37,560
So we have couple of ways of defining a function.

21
00:01:37,560 --> 00:01:43,530
So come here says ways of declaring or creating a function.

22
00:01:43,530 --> 00:01:44,730
Ways of creating.

23
00:01:45,620 --> 00:01:46,550
A function.

24
00:01:47,550 --> 00:01:49,440
And we have two ways.

25
00:01:49,440 --> 00:01:52,590
One is using the function.

26
00:01:53,420 --> 00:01:54,420
Declaration.

27
00:01:56,420 --> 00:01:59,660
And then the other one is called function.

28
00:02:02,020 --> 00:02:03,070
Expression.

29
00:02:03,610 --> 00:02:04,420
So.

30
00:02:05,550 --> 00:02:15,420
In this video, let's have a look at a simple function that add two numbers together for now, not add,

31
00:02:15,420 --> 00:02:21,240
let's say, a function to say or to greet somebody say let's say hello.

32
00:02:21,240 --> 00:02:22,200
You are welcome.

33
00:02:22,380 --> 00:02:25,860
And we're going to display that one inside the console.

34
00:02:26,280 --> 00:02:33,420
So let's say create a function to say hello.

35
00:02:34,620 --> 00:02:40,830
JS That so as you remember from here to create that we bring in our function keyword.

36
00:02:40,830 --> 00:02:44,550
So here we go, function keyword here.

37
00:02:44,730 --> 00:02:49,980
The next one is the name of my function as a variable name.

38
00:02:50,100 --> 00:02:55,410
So the name of a function must depict what it does.

39
00:02:55,410 --> 00:03:01,140
So we say say hello, that our function name is that I'm using common cases.

40
00:03:01,380 --> 00:03:07,650
So depending how you want to name your variables, as we discussed before, that is my function name

41
00:03:07,980 --> 00:03:09,120
and my.

42
00:03:10,230 --> 00:03:11,340
Brackets here.

43
00:03:11,610 --> 00:03:16,920
So then I bring my body here as that, and then my carry braces.

44
00:03:17,250 --> 00:03:18,870
That is a function.

45
00:03:18,990 --> 00:03:21,990
Again, this is what you call function declaration.

46
00:03:21,990 --> 00:03:22,830
So let me.

47
00:03:23,650 --> 00:03:24,850
Bring it here.

48
00:03:25,000 --> 00:03:28,330
As call function decoration.

49
00:03:28,360 --> 00:03:30,580
This what you call function decoration.

50
00:03:30,580 --> 00:03:35,650
So inside the codebases is where your code will be here.

51
00:03:36,100 --> 00:03:39,280
So a function to say hello.

52
00:03:40,920 --> 00:03:42,120
So in the body.

53
00:03:42,150 --> 00:03:43,710
That's where I'm going with our logic.

54
00:03:43,710 --> 00:03:49,950
So we just want to console, log, simple message, console, log and say.

55
00:03:51,690 --> 00:03:52,560
Hello.

56
00:03:53,190 --> 00:03:55,920
Work on two functions.

57
00:03:58,440 --> 00:03:59,310
That is it.

58
00:03:59,340 --> 00:04:03,120
So I have created my first function.

59
00:04:03,740 --> 00:04:07,670
So how can I use this particular function?

60
00:04:07,880 --> 00:04:11,210
And that is what you call function invocation.

61
00:04:11,570 --> 00:04:17,029
Meaning calling a function is called function invocation.

62
00:04:17,269 --> 00:04:25,280
So as soon as you create a function well, we have saved the function called say hello in memory of

63
00:04:25,280 --> 00:04:26,180
JavaScript.

64
00:04:26,660 --> 00:04:30,560
So anywhere I want to use this message.

65
00:04:31,600 --> 00:04:35,410
If I call my function, I will say hello.

66
00:04:35,440 --> 00:04:37,200
Welcome to function.

67
00:04:37,210 --> 00:04:44,290
So if I check my calls, the function or what is function is doing that just display this message to

68
00:04:44,290 --> 00:04:45,160
the console.

69
00:04:45,190 --> 00:04:46,840
That's a basic function.

70
00:04:46,840 --> 00:04:48,670
So to be able to view.

71
00:04:48,700 --> 00:04:50,590
Let's open the console.

72
00:04:50,620 --> 00:04:53,860
And now we see that well, this is where.

73
00:04:53,860 --> 00:04:54,260
Right.

74
00:04:54,280 --> 00:04:59,650
Nothing has been shown here because we have not called the function.

75
00:05:00,010 --> 00:05:05,350
So after we create a function, we need to call it or invoke.

76
00:05:05,380 --> 00:05:09,250
So here is create a function here.

77
00:05:10,640 --> 00:05:15,050
And then if you don't call it well, the function will not do anything.

78
00:05:15,080 --> 00:05:19,160
So down here, let's say, calling a function.

79
00:05:20,100 --> 00:05:26,220
Or is our system as function invocation won't invoke the function?

80
00:05:26,250 --> 00:05:28,890
How do we invoke a function?

81
00:05:29,520 --> 00:05:32,070
So to be able to know that.

82
00:05:33,080 --> 00:05:35,080
Certain variable is a function.

83
00:05:35,090 --> 00:05:36,290
Let me show you the clue.

84
00:05:36,410 --> 00:05:40,250
So here to call the function, you bring in your function name.

85
00:05:40,580 --> 00:05:42,110
That is, say hello.

86
00:05:42,800 --> 00:05:44,480
If I do this one, I save it.

87
00:05:44,570 --> 00:05:46,760
So nothing has been shown here.

88
00:05:47,030 --> 00:05:51,920
So to call a function, you need to bring your.

89
00:05:54,140 --> 00:05:56,900
Brackets like that.

90
00:05:56,930 --> 00:05:59,900
Now, with this one, if I save this one.

91
00:06:00,050 --> 00:06:03,260
Now, if you see that, I have.

92
00:06:03,470 --> 00:06:04,080
Hello.

93
00:06:04,100 --> 00:06:05,570
Welcome to function.

94
00:06:05,570 --> 00:06:07,790
Because I have called a function.

95
00:06:08,060 --> 00:06:08,540
Meaning?

96
00:06:08,540 --> 00:06:12,260
I have my square bracket here.

97
00:06:12,500 --> 00:06:14,590
Meaning calling the function.

98
00:06:14,600 --> 00:06:22,400
So anything that we see a variable with this square bracket around it, it tells you it's a function.

99
00:06:22,940 --> 00:06:29,540
So you can see that even console dot now no console dot log.

100
00:06:30,530 --> 00:06:32,860
How will we see about this?

101
00:06:33,230 --> 00:06:39,170
This is a function because look at the curves, the square bracket here we have the square bracket here,

102
00:06:39,170 --> 00:06:41,330
which means it's a function.

103
00:06:41,960 --> 00:06:47,050
So that is pretty much it about how we can create a function, the first one.

104
00:06:47,060 --> 00:06:48,470
Now let's move step by step.

105
00:06:48,650 --> 00:06:54,830
First of all, we knew how to create a function and then we knew how to call a function.

106
00:06:55,400 --> 00:06:59,600
That's the first step about function declaration.

107
00:07:00,410 --> 00:07:03,170
What about function expression?

108
00:07:03,410 --> 00:07:04,820
Where's my function expression?

109
00:07:04,820 --> 00:07:05,170
Yeah.

110
00:07:05,180 --> 00:07:06,230
Here is step number two.

111
00:07:06,230 --> 00:07:09,320
How can we create function expression?

112
00:07:09,500 --> 00:07:11,420
So here is my function.

113
00:07:12,640 --> 00:07:14,110
Expression, perfect.

114
00:07:14,110 --> 00:07:18,100
So how can we create that kind of function function?

115
00:07:18,760 --> 00:07:24,580
So for function expression, we assign a function to a variable.

116
00:07:24,880 --> 00:07:27,460
So the name of this function.

117
00:07:28,290 --> 00:07:31,080
Let me comment about this one or let me leave it.

118
00:07:31,560 --> 00:07:41,580
So this function is going to also, I mean, displace a message and say, yes, I mean, good morning.

119
00:07:41,580 --> 00:07:42,060
Yes.

120
00:07:42,060 --> 00:07:44,490
Just grid a function to grid.

121
00:07:44,520 --> 00:07:45,180
Okay.

122
00:07:45,180 --> 00:07:49,110
So here you bring in your name calling.

123
00:07:49,130 --> 00:07:51,330
So let me show you with this picture here.

124
00:07:51,900 --> 00:07:54,660
So we call this one function expression.

125
00:07:54,720 --> 00:08:04,380
We have our keyword here led and then we have a variable name equal to the function keyword and then

126
00:08:04,380 --> 00:08:11,550
our square bracket and a function body as compared to function declaration we don't have let's we don't

127
00:08:11,550 --> 00:08:17,400
have equal to that is function declaration and this function expression.

128
00:08:17,610 --> 00:08:26,970
So here a function going to be grading I'm going to do somebody and then assign to equal to the name

129
00:08:26,970 --> 00:08:31,860
of my function and my square bracket and my carry basis.

130
00:08:31,860 --> 00:08:38,250
So in here I just console.log something and say good morning.

131
00:08:39,530 --> 00:08:40,270
Perfect.

132
00:08:40,280 --> 00:08:44,890
So let me comment this one out because I don't want to call this function.

133
00:08:44,900 --> 00:08:52,100
So if I save it now, my console is empty because I haven't called this function.

134
00:08:52,100 --> 00:08:58,040
So the way we call function declaration, it is same as calling function expression.

135
00:08:58,250 --> 00:09:02,840
So here I would just bring in my greeting and then call my function.

136
00:09:02,870 --> 00:09:05,630
I start and now I have.

137
00:09:05,630 --> 00:09:06,740
Good morning.

138
00:09:06,770 --> 00:09:10,070
So before we end this video, just have a look.

139
00:09:10,070 --> 00:09:16,490
The two ways of creating a function function, the creation and then function expression.

140
00:09:16,850 --> 00:09:19,400
And after creating, we need to call the function.

141
00:09:19,400 --> 00:09:23,030
These are the two things you need to take note in this particular video.

142
00:09:23,090 --> 00:09:26,060
So let me give you an exercise.

143
00:09:26,570 --> 00:09:26,960
Okay.

144
00:09:26,990 --> 00:09:29,330
So exercise is like this one.

145
00:09:29,600 --> 00:09:35,660
Create a function to greet your mom.

146
00:09:36,480 --> 00:09:38,910
Can say Hello Mom.

147
00:09:38,940 --> 00:09:41,940
Good morning or Hello, Mom, how are you?

148
00:09:42,370 --> 00:09:42,720
Okay.

149
00:09:42,720 --> 00:09:43,800
So create.

150
00:09:44,700 --> 00:09:46,380
Create a function.

151
00:09:47,770 --> 00:09:48,910
To greet Mom.

152
00:09:50,270 --> 00:09:52,910
That is it to any message you want you to get your mom?

153
00:09:52,910 --> 00:09:54,350
Why not go ahead and do it?

154
00:09:54,440 --> 00:09:59,060
So here you can give your function a name the way you want it.

155
00:09:59,060 --> 00:10:02,490
But a name must be descriptive and then just console.log.

156
00:10:02,510 --> 00:10:04,130
I mean, Mom, how are you?

157
00:10:04,160 --> 00:10:04,760
Good morning.

158
00:10:04,760 --> 00:10:05,750
I miss you.

159
00:10:05,780 --> 00:10:06,890
Something like that.

160
00:10:06,890 --> 00:10:08,620
So let's see how you're going to do this one.

161
00:10:08,630 --> 00:10:09,120
In this video.

162
00:10:09,120 --> 00:10:14,480
And in this video, you solve it and talk about another key concept when you come to function.

163
00:10:14,480 --> 00:10:15,440
The next video.

