Skip to content

OutputNot attempted

arguments and a promise that resolves synchronously

function foo() {
const args = Array.prototype.slice.call(arguments);
console.log(args[1], arguments.length, Array.isArray(arguments));
}
foo(1, 2, 4);
let a, b;
const p = new Promise((res) => {
a = setTimeout(() => res('hi'));
b = setTimeout(() => res('hello'));
res(3);
});
clearTimeout(a);
p.then((v) => console.log('result', v));

Spaces and quote style don’t matter · write a thrown error as TypeError

Ctrl Enter
Show answer & explanation

The expected output comes from actually running the snippet; opening this shows it next to the explanation.

arguments is array-LIKE (has length, isn't an Array), so borrow slice or use rest parameters instead. The executor's synchronous res(3) settles the promise first; the timer resolves would be ignored even if they ran.