helpermethod
helpermethod

Reputation: 62214

Strange JSLint error when testing code snippet

When I test this code snippet in jsFiddle with JSLint, it gives me this strange warning:

Problem at line 3 character 10: Cannot set property 'first' of undefined

But if I declare the variable currentNumber outside of (i.e. before) the for-loop, it doesn't complain.

What is the reason of this?

Upvotes: 1

Views: 640

Answers (2)

Jere
Jere

Reputation: 3397

JSLint will want var declarations at the top of functions. The particular error you're getting in jsfiddle is odd, but a complaint from JSLint isn't unexpected at all.

Problem at line 3 character 6: Move 'var' declarations to the top of the function.

http://www.jslint.com/

Warning!

JSLint will hurt your feelings.

...

The var statements should be the first statements in the function body.

Upvotes: 2

mergeconflict
mergeconflict

Reputation: 8276

Looks like a bug in jsFiddle or JSLint, honestly... If I try for (var i = 0; i < 10; ++i) {} it gives the same error. If I take out var it stops complaining.

Upvotes: 3

Related Questions