Hoisting is JavaScript's default behavior of moving all declarations to the top of the current scope (to the top of the current script or the current function).

function number() {
    return 1;
}

(function() {
    try {
        number();
    } catch (ex) {
        console.log(ex);
    }
    var number = function number() {
        return 2;
    };

    console.log(number());
})();

console.log(number());

js会把声明提升到当前作用域的最上边,包括变量和函数声明。

function number() {
    return 1;
}

(function() {
    console.log(number());

    function number() {
        return 2;
    }
})();

console.log(number());

相关文章:

  • 2021-12-22
  • 2022-12-23
  • 2021-05-31
  • 2021-11-17
  • 2021-07-12
  • 2022-12-23
  • 2021-09-29
猜你喜欢
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2021-08-24
  • 2021-09-06
相关资源
相似解决方案