+ 1
Explain Output Of This Code?
function func(a,b=1,c=3) { return (a+b+c)%3; }; document.write(func(2,4));
4 ответов
+ 6
Possible output of this code is 0.
This function uses ES6 default parameter values. so when you call func(2,4) it will be called like this func(2,4,3)
so, (a + b + c) % 3 = ( 2 + 4 + 3) % 3 = 9 % 3 = 0
+ 5
% is reminder operator in Javascript. Check this link, you will know
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
0
why 9%3 =0 ?
0
% gives the remainder.
when 9 is divided 3 ..we get quotient as 3 and remainder as 0.