代码之家  ›  专栏  ›  技术社区  ›  Andrey Bushman

为什么我的变量没有初始化值?

  •  3
  • Andrey Bushman  · 技术社区  · 7 年前

    我初始化我的常量 index 变量(在 case 代码块)返回的表达式 2 指数 价值是 undefined ... 怎么可能?

    我通过 create-react-app src 子目录。

    我在这里发布了示例的代码源: https://github.com/Andrey-Bushman/i-learn-redux (您可以通过 npm start yarn start 命令)。

    enter image description here

    控制台输出:

    enter image description here

    这个 findIndex

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  3
  •   Daniel Hilgarth Richard    7 年前

    这是Chrome开发工具中的一个bug。 index 有价值吗 2 -你会注意到这一点,如果你 console.log(index) . 看起来Chrome DevTools的 指数 变量在此函数中定义了两次。
    如果重命名一个引用,Chrome DevTools将显示正确的值。

    Local 您将看到另一个变量 _index 具有正确的值。