Why does WebStorm say these lines are duplicate declarations?

I’ve got this code in my Meteor app:

var step = Session.get(‘stepNum’),
step = (step) < 5 ? ++step : 1;

WebStorm’s inspection claims that both lines are duplicate declarations (telling me, “Duplicate declaration (at line 77)” and “Duplicate declaration (at line 78)

Why? This is a common pattern, declaring a var and subsequently changing its value via further assignments.

Is WebStorm thinking that “var step” is a local var, and “step” is a global, or what and, if so, what is the proper way to do this in JavaScript/Meteor?

The comma is the problem.

End your first line with a semicolon

Its seeing this:

var step = Session.get('stepNum'),
var step = (step) < 5 ? ++step : 1;
1 Like

Thanks; the font was so small in WebStorm I didn’t notice that.