'JavaScript Code Linting tool to find Variables which are initialised but might not be used due to condition
I have the following JavaScript code,
var foo = {
company: "ABC",
name: "John"
};
var att = "";
function test(ob, i) {
var m = JSON.stringify(ob);
if (i < 10) {
att = att + m;
}
}
test(foo, 20);
In above code, var m = JSON.stringify(ob); line is unnecessary initialisation of variable when i < 10 is not true. A better code will be to move the initialization inside the if condition.
I am not able to find a code linter that can detect such scenarios. In such cases, I want a warning that variable might not be used. Does anyone know any linting tool that can do this?
I tried
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
