由于javascript变量提升,jshint抱怨:
function test() {
...
if( cond1 ) {
var a = ...
//do something with a
}
...
if( cond2 ) {
var a = ...
//do something with a
}
...
}
因为它相当于:
function test() {
var a;
var a;
...
if( cond1 ) {
a = ...
//do something with a
}
...
if( cond2 ) {
a = ...
//do something with a
}
...
}
第一种方法是否会导致某些代码出现错误?