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