Closed TitanNano closed 10 years ago
I think that is dafault behavior of JSHint, this bracket plugin dont change JSHint, only use it.
Javascript has function-level scope, diferent from other C-like languages that are block-level scope like Java and C#
For more information about this you can read this article: http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html
The correct code to by pass this JSHint warnings is
var x;
if (a == b) {
x = 1;
} else {
x = 2;
}
console.log(x);
thats all true but the thing is that when "a != b", "var x= 1" never will be executed so "var x=2" will not be a redefinition.
@TitanNano Javascript does not have block-scope level, only have function-scope level Independly wheather first or second statement will be executed, these two statements will share variable declarations.
I just entered this in my console:
var test= false;
if(test){
var x= 0;
}else{
console.log(x)
}
"console.log" will print out 'undefined' because x never was defined!
@TitanNano I understand your point of view, but jshint does not an interpreter at all, it's just a javascript analytic tool that dont parse code results, jshint only have the meaning to alert for the bad practices, if you do some code that have two variables declarations with the same name in the same function scope, jshint will warn them to you without take knowledge of the code semantics.
its just to keep maintenability of your code and following one way to code in js and avoid problems with readability
moving to jshint/jshint#1471
Hey,
If you make something like this:
he will complain about redefining of x. But I think he should detect that x always only once will be defined.