下⾯ JavaScript 代码的输出是什么?

const foo = () => console.log("First");
const bar = () => setTimeout(() => console.log("Second")
const baz = () => console.log("Third");
bar();
foo();
baz();
    878 次浏览
    • A、First Third Second
    • B、First Second Third
    • C、Second First Third
    • D、Second Third First
    我们有⼀个 setTimeout 函数并⾸先调⽤它。 然⽽却最后打印了它。 这是因为在浏览器中,我们不只有运⾏时引擎,我们还有⼀个叫做 WebAPI 的东西。 WebAPI 为我们提供了setTimeout 函数,例如 DOM。 将 callback 推送到 WebAPI 后, setTimeout 函数本⾝(但不是回调!)从堆栈中弹出。
    挑战成功
    2年前
    挑战成功
    5年前