In the earlier lesson, we briefly looked at declarations versus expressions and for the most part,
the type of function that we've been writing are the declaration ones.
And this is also depending on the preference of the developer, you may choose to use the expressions
or the declarations.
They're both going to accomplish the same thing, although it's going to look a little bit different
within the format.
So some developers will prefer to use expressions and depending on how you want to use them.
Also, keep in mind, if you are using function declarations, they are hoisted to the top of the code.
So that means that we don't have to worry about where we place them.
So in this example, we've got will not work, not hoisted.
And we see that when we've got the expression function, we're not able to work.
We already saw that earlier, one of the examples.
But over here we see where we've got test to that we're invoking.
And this one will work because this is a declaration.
So this can sit anywhere in the code.
So it gives you a little bit more flexibility when you're writing your code to separate it out.
And you can create a whole list of functions and then you can use them.
And a lot of times when you've got JavaScript libraries or separate JavaScript files there, declaration
functions.
So you don't have to worry about that.
The where the library is placed, as long as you're linking to the JSC file, then you're able to use
all of the functions.
So there are benefits and there are advantages to using either one.
And again, it's up to personal preference as well as a developer.
So if you do see that error, then if you are using expression, then that means that you just haven't
created the expression to find the expression before you're trying to use it in this exercise.
And this challenge is to create two functions, one as a function declaration and the one the one as
an expression.
They can both add a value to a number and they should both work the same way.
So depending doesn't matter which one we call upon, they should both have an output of ten.
So obviously, for this example, we're passing in five, it's adding five and it's OK putting it into
the console.
So go ahead and try that project out.
And just so you get more familiar with the different ways to write functions and I'll walk you through
it.
So go ahead, pause the video and I'll walk you through it.
Coming up, the function.
So this one can be test and it's expecting parameter to be passed.
And so it's expecting a number and they're both doing the same thing where they're returning a value
and then just adding five to it.
And we can console logout test one and console log test two and will pass and five.
And we now need to define that other function.
So let's test two.
And it's taking a number that's being passed in and that's doing the exact same thing where it's taking
that value that got passed in and adding five to it.
So try it out.
And we see within the console we've got two tenths.
Next lesson we're going to be discussing function scope.
So let's come up.