Chris Jones
Chris Jones

Reputation: 672

JSLint says Variable not used and one not initialized but JSHint doesn't say that?

I am having an issue where I can't get this function to run. I decided to check out JSLint on a program to see if there was something I missed. It turns out JSlint says

function objCount(obj) {
    var bra,
        count;
    for (bra in obj) {
        count++;
    }
    return count;
}

has bra as unused and it also says I didn't initialize count.. I really cannot figure out why. JSHint however did not give me an error with this at all.The basic idea of this function is to just tell you how many properties there are in an object. Any ideas?

Upvotes: 1

Views: 65

Answers (1)

Matthew
Matthew

Reputation: 263

I'm not sure about bra but you can't increment count because it is not initialized to a number.

For example, you should initialize count then increment it.

function objCount(obj) {
    var bra,
        count = 0;
    for (bra in obj) {
        count++;
    }
    return count;
}

That worked for me.

Upvotes: 1

Related Questions