Now it's time to consider another very helpful and convenient feature which was released in Essex,
I'm going to talk about default parameters.
Let's go to Brackett's and create function.
Let's call that person.
And insert here three parameters, first name, last name and profession.
Then running council.
Right, I am right, first name.
Then last name, then the text, and I am and place your thought parameter profession.
Then invoke this function and as an argument, let's place here on the first name, for example, John,
so as you see, function has three parameters, but as arguments, we have only one.
If we reload, we will get I am John.
But as for a last name and profession we have here undefined.
The reason is that we did not insert the rest of the arguments.
JavaScript engine found here one argument and as a default, it has been represented as the first parameter
first name.
In order to fix that in ESPIED, we have several ways.
First one is to use a statement and as a condition we have to place your last name.
Three equals to undefined.
So if this condition is true, we need to assign the value to last name parameter.
For example, as Smith.
The exact same thing we have to do for third parameter, which is profession, so creative statement
as a condition, right profession to people equals to undefined.
So, again, if this condition is true, then we need to right.
Profession equals to, let's say, programer.
So if we reload the page, we will get the results, what we wanted.
I'm John Smith and I am programer.
OK, now let's insert second and third arguments and rights.
For example, though, as last name and then instructor as profession.
Reload the page.
And we have I'm John Doe and I am an instructor.
In this case, the conditions in if statements were false.
So the code inside them was executed and we got the result with a different last name and profession.
So this is one way to fix that problem.
But besides that, instead of if statements we can use logical or operator and achieve the same results,
let's do it for professional parameter delete if statement and instead of it.
Right profession equals to profession or programmer.
This is kind of short wait and using your statement, so when we invoke function, if we insert their
third argument, then parameter profession will take relevant value.
But if we miss that parameter, then it will take as a value programmer.
So reload the page and we have the same result because the third argument is defined, but if we delete
it.
Then we will get programer as a value of profession.
All right, this is the way how we could work with parameters in S5.
Honestly, it wasn't so bad, but ethics offers us much better way.
We don't need if statements or logical or operators anymore, we can simply assign the default values
to parameters when we create them.
So right here, first name equals to John, then assign Smith to last name and for profession.
Right programmer.
Also, delete the arguments below.
Revolt and we have default parameter values and George Smith and I am programer, so those are default
parameters with default values.
But of course, if we insert here arguments, for example, as first name Niek, that though as last
name and instructor for profession, then they will be overwritten to default values and will get I
am Nito and I am instructor.
So this is the main use case of default parameters in ethics.
I'm not going to go further and write some crazy examples.
I think it's quite enough to be able to use them in future.
So let's move on.