Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does "variable initializer is redundant" mean?

Tags:

javascript

So I am using Webstorm IDE for some JavaScript and I believe it uses JSLint to inspect the code. I have a bunch of variable initializer is redundant warnings. I can't find anything about what it exactly means in terms of what I need to fix.

Example:

function calcPayNow(){
    var payNowVal = 0;
    --snip---
    payNowVal = (Math.round(tec * x) - Math.round(allpmts * x)) / x;
   --snip--
}
like image 289
dbinott Avatar asked Aug 20 '15 16:08

dbinott


1 Answers

It means that there is no purpose to assigning 0 because it is never used before you assign a different value.

I would change it from:

var payNowVal = 0;
--snip---
payNowVal = (Math.round(tec * x) - Math.round(allpmts * x)) / x;

to

--snip---
var payNowVal = (Math.round(tec * x) - Math.round(allpmts * x)) / x;
like image 82
dsh Avatar answered Sep 23 '22 07:09

dsh