I am not at all able to decode the output for this js code snippet. The output actually shows 3 . I expected output to be 4. Can someone please explain what is going on here, or am I missing some crude concept of javascript.
var length = 4;
function callback() {
console.log(this.length);
}
const object = {
length: 5,
method() {
arguments[0]();
}
};
object.method(callback, 1, 2);
arguments.lengthbecause it was called as a method ([0]) ofarguments.alert(1)– the argument list is(1)), and the “parameters” belong to the function itself (function foo(bar) {}– the parameter list is(bar)). Anyway, you mentionedFunction.lengthand linked to thelengthproperty of functions, but what’s being read here isarguments.length(thisinsidecallbackis equal toargumentsinsidemethod), andargumentsis not a function.