0
function
Let addition=function(num1=20,num2){ sum=num1+num2; return sum; } Let result =addition(, 30); console.log (result) In calling only second parameter,first parameter is give given by optional parameter. How to give it
18 Answers
+ 1
Oh okay, yes, for the second example it is correct. The first argument will be 30, the second argument will use the default value (50).
+ 1
It's not possible buddy ...
I told you that before, optional parameters (which have default values) must be placed after all the mandatory parameters (which values must be given).
+ 1
No buddy, it's awkward for a code to look like that ...
0
Optional parameter(s) ideally should be placed after mandatory parameter(s), not the other way around.
0
Let addition=function(num1,num2=50){
sum=num1+num2;
return sum;
}
Let result =addition(30);
console.log (result)
I need this type answer above
0
Same like I have calling with only second parameter, optional parameter value is given first one
0
For that one, `addition` will be called with 30 as <num1> and 50 as <num2>. The function will return sum of <num1> added b6 <num2> that is 30 + 50.
0
Yes same like how to apply second calling parameter.
0
I didn't get your point ...
0
In this case we calling first parameter, we had given second parameter is optional is it wright
0
Same way,
We calling second parameter, we had given first parameter is optional value is given. How it works... How it given
.
0
I nedd, for according to the very first example . the first argument will use the default value (10).the calling with only second argument is it possible
0
OK thank you. Finally one doubt
0
But we use calling like
Addition(undefined, 50) is it currect, use this way
0
But executed successfully. Is it currect
0
`undefined` is not a number, I can see that it works, but passing `undefined` to replace a numeric argument (even optional and has default value) doesn't seem like a good practice.
0
OK thank you so much for your help.
0
Ok buddy no prob 👌