Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSLint Error Report - Whats wrong with this?

I got this error and dont know what could be the cause. Any idea?

Problem at line 2127 character 18: Bad for in variable 'sport'. for (sport in sugested_sports)

                // make array
        var sugested_sports = data.split(",");

            // pre build DIV
        var sporty_items = '';
        for (sport in sugested_sports)
        {
            if  (sugested_sports.hasOwnProperty(sport)) {
                sporty_items += '<a href="#'+identifier[1]+'">'+sugested_sports[sport]+'</a>';
            }
        }
            // insert DIV
        DIVsuggestions.html(sporty_items);

thx alot.

like image 374
Hans Avatar asked May 22 '10 02:05

Hans


People also ask

What is Jslint used for?

JSLint is a static code analysis tool used in software development for checking if JavaScript source code complies with coding rules. It is provided primarily as a browser-based web application accessible through the domain jslint.com, but there are also command-line adaptations.

What is the difference between Jslint and ESLint?

ESLint: The fully pluggable JavaScript code quality tool. A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease; JSLint: A Code Quality Tool for Javascript.

What is function form of use strict?

The "use strict" Directive It is not a statement, but a literal expression, ignored by earlier versions of JavaScript. The purpose of "use strict" is to indicate that the code should be executed in "strict mode". With strict mode, you can not, for example, use undeclared variables.


1 Answers

Try

var sport;
for (sport in sugested_sports)

This takes care of the missing variable declaration and places it outside the for loop ( see jsLint error "Cannot set property 'first' of undefined" ).

like image 148
Pointy Avatar answered Oct 11 '22 23:10

Pointy