Why does not JSLint allow “var” in a for loop?

前端 未结 3 658
离开以前
离开以前 2021-01-14 08:03

Something is wrong with my code or with plovr. I went to JSLint to get some help. However, JSLint seems to consider this as a fatal error and refuses to check more of the co

3条回答
  •  别那么骄傲
    2021-01-14 08:43

    Because creating a bar in the for loop creates a global var. it's one of those things that JavaScript does and most people don't realize. And if you don't and you or someone else creates that same var in the scope of that function or global scope then that my friend would be one of the famous JavaScript foot guns.

提交回复
热议问题