say I have this:
function write3(a, b, c) {
document.write(a + " " + b + " " + c);
}
var arr = [1, 2, 3];
var i = 0;
write3(arr[i++], arr[i++], arr[i++]);
It results in 1 2 3 as expected, however, I'm not sure that this is guaranteed behavior. Could the arguments passed to write3 hypothetically be resolved in any other order than left to right?
Yes, the order of argument evaluation is guaranteed to be left-to-right.
According to sections 11.2.3 and 11.2.4 of the ES5 spec, function arguments are Argument Lists, and Argument Lists should always be evaluated left to right.
Specifically, the function to call gets evaluated, and then the function's arguments are evaluated from left to right.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments