Let's stick to functions.
Another nice feature which is available in modern javascript is that you can assign default arguments
to function parameters.
Let's say you're in our add function.
For some reason be one of a default value for b.
So we know we want to be able to add two numbers together but in case you call this function with only
one number we'll assume a default for the second argument or for the second parameter.
We can do so by adding a equals on year in the parameter list and then setting our default value which
of course has to match our type.
For example 1 or whatever the default should be.
And now it does enables us to call this function with only one argument so I could call it like this
and typescript would not complain because it detects that we have a default argument here which is then
taken for a b and therefore here I get output of 6 because my default B is 1 and I add 5 which makes
6.
Now one important note about default arguments here they have to be lost in the list.
If you assign a default argument to a for example we'll have an issue why.
Because default arguments are not skipped when you call a function.
So if I call the function here with one argument then the arguments and passing in here are passed to
the parameters in the same order.
So calling the function with 1 argument 5 and this case passes does one argument to the first argument
here in the parameter list and since the second argument is not provided with a default it's not optional
and hence we provide no second argument at all.
So typescript or JavaScript actually does not look at your function definition and guess that you probably
want to skip the default argument and provide your value to the non default one.
Instead it simply adheres to the order and therefore you should set defaults from the right.
So make sure that the parameters for what you don't accept default arguments come first before your
default parameters.