javascript - What problems could occur declaring a variable inside an if condition twice? -


what problems occur declaring variable inside if condition twice?

i understand not best way of doing it!
know can declare variable outside if condition.

i'm not looking solution! i'm not looking how can declare variables. want understand why bad approach declare variable inside if-condition block.

/* yes know can have condition instead of condition === true,     simplicity */ if(condition === true){      var stuckups = "over 9000"; }else if(condition === false){     var stuckups = "nothing"; }  alert(stuckups) /* yes can access outside if condition!*/ 

why bad habit if 1 condition executed, means variable declare once anyway. real problems it?

you correct it's not wrong, specified in ecmascript, hoisted top of nearest function definition.

this lead problems when having large codebase , "hard" find.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -