Welcome back to functions in this lesson, we're going to look at parameters and multiple arguments,
so arguments are the parameters when they get passed into to the function and we look at them within
the syntax of the function.
So then they're known as arguments.
So it's the same thing.
Function parameters, so they're inside the parentheses and as we saw, that argument's received by
the function when it's invoked, so we've got the parameter when it's coming in.
And then also it's known as an argument when it's being invoked.
So it's the same thing, but different names for it.
The function can also have multiple parameters.
So we can have parameter one, two, three.
Notice that the comma separated and the structure is the same where we still have that code that's being
executed.
So you can also pass in default arguments.
So there's a number of ways to do that and going to be exploring those as well.
So we've got some examples here.
So by default before now, with the newer version of JavaScript, we do have an option to have a parameter
and equal to a value.
So that can set the value.
And before, if we want to be more compatible with older browsers, there's some other ways to do that
as well, where we can do a conditional statement here so that if we if NUM two is undefined, then
it will equal five.
So we've got the value of num to or five.
So this is another way to set a default typeof num two and if type of num to is undefined we use a territory
operator.
So there is a challenge for this lesson.
So using your knowledge of the earlier lessons, create three different ways to set a default value.
If a function is missing an argument value, they should all produce the same output.
And we just showed you that there are three different ways to do that.
So go ahead, pause the video, open up your editor and try it out.
And that's also important here to practice passing in those arguments, taking those values and then
making use of them within the code.
So let's set up three different functions and we can call them whatever we want.
In this case, we're going to call it out or one.
So this one is going to take No.
One.
It's going to take number two.
So just like on our example and we want to set a default value for number two.
So we are using a more modern browser.
So we do have access to use the default argument so we can set up with assigned value of five.
So in this case, will output both those values as into the console so we can have no one can be equal
to whatever the value that's being passed in of number one.
And then the other one in the console is going to say, number two, it's going to be whatever value
of number two is being passed, a few functions that are going to run.
So in one case, we can pass in one hundred and one hundred.
So we pass on both of the arguments.
And then the other case, what we'll do is we'll just pass on one hundred and see what happens.
And we got to still correct that.
So that should be two.
So let's see what the output is.
So refresh, we're getting number one as one hundred, number two as one hundred.
And in this case, we didn't pass in a second argument.
But we are getting that default of five.
So you could also do something where you've got a default for both of them.
And if you're not passing in anything, then you can see that the result is the same.
So you do have that option.
So the other one that we want it to do is we want to do another function and we can call this one add
or two.
And this is going to take in those same two arguments.
And this is four older versions of browsers that might not have this default argument value here, where
we're going to use a conditional statement to check to see if NUM two is equal to a value.
So if there is a value here, then it's just going to assign that value.
If there's no value there, then it's going to sign the value of five to it and we can try that in this
case as well.
So just update this to number two.
Number two, and in this case, we do need to pass the first argument and you can see that it sets a
default for the second one.
And we'll try one last one.
And this is the one that's also more commonly used as well, where we actually check the type of number
two, so do type of number two.
And if the type is not equal to undefined, then all we do is we just output number two.
So that means that there is a value there.
Otherwise we're going to set a value of five and we'll try this one out as well.
And I'll update this to 100.
So we refresh it.
And you see, in this case, we do pass one hundred and one hundred and then this one is equal to one
hundred, and the second value is being set by default.
So coming up, even more on functions coming up in the next lesson.