Hi all!
I just finished the Symmetric Difference challenge but came across something involving the “arguments” object while working it that I don’t understand.
I’ve outlined the core of the problem below in case anyone that hasn’t done the challenge knows the answer to this question.
When I execute the following function,
function test () {
var ans = 1;
if (arguments[1] == arguments[0]) {
ans = 2;
}
return ans;
}
test(1, 1);
the function returns 2. However, if I execute the exact same function but change the arguments as follows,
function test () {
var ans = 1;
if (arguments[1] == arguments[0]) {
ans = 2;
}
return ans;
}
test([1, 2], [1, 2]);
the function returns 1.
Why exactly does this happen?