0
Por que el resultado es 2 ? / Why the result is 2 ?
function calc ( i ) { return ( i + i ) % 3; } for ( var i = 1; i < 4; ++i ) {} console.log ( calc ( i ) ); salida / output = 2
1 Odpowiedź
+ 6
The for-loop body is empty, so it only increases value of <i>. By the time the for-loop is done, value of <i> would be 4. Inside `calc` function, argument <i> is 4 so
( 4 + 4 ) % 3
8 % 3
And there you have 2, as a remainder of dividing 8 by 3.