+ 1

function (a,b=5,c=6,d=10){ return a+b-d; } document.write(x(30,20));

plz tell procedure..hw to solve this??..thnx

30th Nov 2016, 9:39 PM
Tanaji Kolekar
Tanaji Kolekar - avatar
3 Respuestas
+ 5
b, c and d are default function parameters. Default function parameters allow formal parameters to be initialized with default values if no value or undefined is passed. In your case you did not pass values for c and d parameters. They will be initialized with default values. As a result: function x(a,b=5,c=6,d=10) { // a=30 // b = 20 // c = 6 // d = 10 return a+b-d; // 30 + 20 - 10 = 40 } document.write(x(30,20)); // 40
30th Nov 2016, 10:19 PM
Vladimir Honcharenko
Vladimir Honcharenko - avatar
+ 2
these are default values of the function's parameters which means if you declare it and when you call function with some values that you're passing to it, the function automatically and respectively from left ro right assignes the values to the parameters and if you miss some of them, it use the default values in the function :)
1st Dec 2016, 1:52 AM
Nima Moradi
Nima Moradi - avatar
0
thanks both..I am happy with this answer
1st Dec 2016, 5:12 AM
Tanaji Kolekar
Tanaji Kolekar - avatar