1
00:00:00,210 --> 00:00:06,030
In the earlier lesson, we briefly looked at declarations versus expressions and for the most part,

2
00:00:06,030 --> 00:00:09,150
the type of function that we've been writing are the declaration ones.

3
00:00:09,390 --> 00:00:15,060
And this is also depending on the preference of the developer, you may choose to use the expressions

4
00:00:15,060 --> 00:00:16,290
or the declarations.

5
00:00:16,470 --> 00:00:20,640
They're both going to accomplish the same thing, although it's going to look a little bit different

6
00:00:20,640 --> 00:00:21,630
within the format.

7
00:00:21,810 --> 00:00:27,810
So some developers will prefer to use expressions and depending on how you want to use them.

8
00:00:28,440 --> 00:00:34,440
Also, keep in mind, if you are using function declarations, they are hoisted to the top of the code.

9
00:00:34,690 --> 00:00:38,200
So that means that we don't have to worry about where we place them.

10
00:00:38,430 --> 00:00:41,910
So in this example, we've got will not work, not hoisted.

11
00:00:42,060 --> 00:00:47,700
And we see that when we've got the expression function, we're not able to work.

12
00:00:47,710 --> 00:00:50,010
We already saw that earlier, one of the examples.

13
00:00:50,310 --> 00:00:54,750
But over here we see where we've got test to that we're invoking.

14
00:00:54,750 --> 00:00:59,630
And this one will work because this is a declaration.

15
00:00:59,640 --> 00:01:01,350
So this can sit anywhere in the code.

16
00:01:01,560 --> 00:01:05,760
So it gives you a little bit more flexibility when you're writing your code to separate it out.

17
00:01:05,850 --> 00:01:09,210
And you can create a whole list of functions and then you can use them.

18
00:01:09,330 --> 00:01:15,900
And a lot of times when you've got JavaScript libraries or separate JavaScript files there, declaration

19
00:01:15,900 --> 00:01:16,470
functions.

20
00:01:16,950 --> 00:01:18,720
So you don't have to worry about that.

21
00:01:19,380 --> 00:01:24,960
The where the library is placed, as long as you're linking to the JSC file, then you're able to use

22
00:01:24,960 --> 00:01:26,030
all of the functions.

23
00:01:26,220 --> 00:01:30,060
So there are benefits and there are advantages to using either one.

24
00:01:30,210 --> 00:01:33,650
And again, it's up to personal preference as well as a developer.

25
00:01:33,900 --> 00:01:39,960
So if you do see that error, then if you are using expression, then that means that you just haven't

26
00:01:40,890 --> 00:01:45,570
created the expression to find the expression before you're trying to use it in this exercise.

27
00:01:45,570 --> 00:01:51,120
And this challenge is to create two functions, one as a function declaration and the one the one as

28
00:01:51,120 --> 00:01:51,930
an expression.

29
00:01:52,500 --> 00:01:57,570
They can both add a value to a number and they should both work the same way.

30
00:01:57,580 --> 00:02:03,240
So depending doesn't matter which one we call upon, they should both have an output of ten.

31
00:02:03,270 --> 00:02:09,810
So obviously, for this example, we're passing in five, it's adding five and it's OK putting it into

32
00:02:09,810 --> 00:02:10,440
the console.

33
00:02:10,680 --> 00:02:12,750
So go ahead and try that project out.

34
00:02:12,870 --> 00:02:17,790
And just so you get more familiar with the different ways to write functions and I'll walk you through

35
00:02:17,790 --> 00:02:18,000
it.

36
00:02:18,010 --> 00:02:20,460
So go ahead, pause the video and I'll walk you through it.

37
00:02:20,470 --> 00:02:21,910
Coming up, the function.

38
00:02:21,940 --> 00:02:26,490
So this one can be test and it's expecting parameter to be passed.

39
00:02:26,490 --> 00:02:31,560
And so it's expecting a number and they're both doing the same thing where they're returning a value

40
00:02:31,770 --> 00:02:33,720
and then just adding five to it.

41
00:02:33,840 --> 00:02:42,660
And we can console logout test one and console log test two and will pass and five.

42
00:02:42,870 --> 00:02:45,090
And we now need to define that other function.

43
00:02:45,100 --> 00:02:46,380
So let's test two.

44
00:02:46,800 --> 00:02:53,640
And it's taking a number that's being passed in and that's doing the exact same thing where it's taking

45
00:02:53,640 --> 00:02:57,180
that value that got passed in and adding five to it.

46
00:02:57,450 --> 00:02:58,230
So try it out.

47
00:02:58,230 --> 00:03:01,050
And we see within the console we've got two tenths.

48
00:03:01,440 --> 00:03:03,960
Next lesson we're going to be discussing function scope.

49
00:03:04,080 --> 00:03:04,830
So let's come up.
