Is it wrong to declare a variable inside an if statement in Javascript?

前端 未结 7 689
被撕碎了的回忆
被撕碎了的回忆 2020-12-21 11:49

I have a Sublimelinter installed in Sublime Text 2 and it\'s great. However it doesn\'t like the following code:

if(condition){
    var result = 1;
}else{
           


        
7条回答
  •  粉色の甜心
    2020-12-21 12:06

    Declare your var pointer once with-in the function you have your if statement at. Like ninjagecko mentioned all vars get sent to the top of their containing functions.

    However; do be careful because if you declare the same var twice like you have it , it will reset the var.

提交回复
热议问题