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

23rd Jul 2020, 2:18 AM
vardhan js
vardhan js - avatar
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).
23rd Jul 2020, 2:50 AM
Ipang
+ 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).
23rd Jul 2020, 2:57 AM
Ipang
+ 1
No buddy, it's awkward for a code to look like that ...
23rd Jul 2020, 3:01 AM
Ipang
0
Optional parameter(s) ideally should be placed after mandatory parameter(s), not the other way around.
23rd Jul 2020, 2:36 AM
Ipang
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
23rd Jul 2020, 2:39 AM
vardhan js
vardhan js - avatar
0
Same like I have calling with only second parameter, optional parameter value is given first one
23rd Jul 2020, 2:42 AM
vardhan js
vardhan js - avatar
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.
23rd Jul 2020, 2:44 AM
Ipang
0
Yes same like how to apply second calling parameter.
23rd Jul 2020, 2:46 AM
vardhan js
vardhan js - avatar
0
I didn't get your point ...
23rd Jul 2020, 2:47 AM
Ipang
0
In this case we calling first parameter, we had given second parameter is optional is it wright
23rd Jul 2020, 2:47 AM
vardhan js
vardhan js - avatar
0
Same way, We calling second parameter, we had given first parameter is optional value is given. How it works... How it given .
23rd Jul 2020, 2:49 AM
vardhan js
vardhan js - avatar
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
23rd Jul 2020, 2:53 AM
vardhan js
vardhan js - avatar
0
OK thank you. Finally one doubt
23rd Jul 2020, 2:58 AM
vardhan js
vardhan js - avatar
0
But we use calling like Addition(undefined, 50) is it currect, use this way
23rd Jul 2020, 3:00 AM
vardhan js
vardhan js - avatar
0
But executed successfully. Is it currect
23rd Jul 2020, 3:02 AM
vardhan js
vardhan js - avatar
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.
23rd Jul 2020, 3:10 AM
Ipang
0
OK thank you so much for your help.
23rd Jul 2020, 3:11 AM
vardhan js
vardhan js - avatar
0
Ok buddy no prob 👌
23rd Jul 2020, 3:34 AM
Ipang