Understanding JavaScript hoisting and truthy & falsy

后端 未结 2 910
一整个雨季
一整个雨季 2020-12-11 05:23

I\'ve been reading about JavaScript hoisting sometime back.

JavaScript Scoping and Hoisting by Ben Cherry
Two words about “hoisting” by Dmitry Soshnikov

2条回答
  •  难免孤独
    2020-12-11 06:05

    Only variable declaration is eagerly evaluated. The variable assignment in your first case (in the if block) occurs only upon entering the if block.

    The variable you only declare, but not assign any value to, has the value of undefined (which coerces to false).

提交回复
热议问题