Cannot reuse variable in for in loop if it has been used in a function of a previous for in #817

jtheoof opened this Issue Jan 18, 2013 · 1 comment

2 participants

(function () {
    /*jshint loopfunc:true */

    "use strict";

    var field,
        obj = { a: 1, b:1 };

    for(field in obj) {
        if (obj.hasOwnProperty(field)) {
            var print = function() {

    for(field in obj) {
        if (obj.hasOwnProperty(field)) {


If you try to validate this code with jshint, it will generate the following error:

test.js: line 18, col 13, Bad for in variable 'field'.

The reason seems to come from the fact that I use field in print function, if I remove it jshint does not generate any error.

I don't see any reason why reusing field as for in variable is bad.

Could it be a bug in jshint?

JSHint member

This bug was fixed in 2.5.7

@lukeapage lukeapage closed this Jun 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment