+ 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
3 odpowiedzi
+ 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
+ 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 :)
0
thanks both..I am happy with this answer