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

前端 未结 7 642
被撕碎了的回忆
被撕碎了的回忆 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:16

    No it is not "wrong"; it will get hoisted to the top of the nearest function definition, as per the ECMAScript specification.

    Yes, your program "Sublimelinter" is incorrect to claim the variable is out of scope.

提交回复
热议问题