Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to silence JSHint's "variable is already defined" warning?

Tags:

JSHint complains if I have multiple for loops declaring the same index variable:

for(var i=0; i<10; i++){     console.log(i); }  for(var i=0; i<10; i++){   //<-- jshint warns that 'i' is already defined     console.log(i); } 

Is there a way to turn this warning off? I couldn't find any when I searched...

The reason I want to do this is that I prefer keeping my index variables declared together with the loops instead of hoisting the declarations to the top of the function. I think repeating the declarations is more robust if I delete the for loops or move them around and I also think it helps convey the intention that the loop variables should not be used outside the loops.

like image 398
hugomg Avatar asked Aug 03 '14 06:08

hugomg


1 Answers

The shadow option disables this warning.

/* jshint shadow:true */  for(var i=0; i<10; i++){ console.log(i); } for(var i=0; i<10; i++){ console.log(i); } 
like image 124
hugomg Avatar answered Sep 27 '22 18:09

hugomg