For example, after spending an hour on the following javascript logic error, I finally realized the problem. Keep in mind that this if statement is embedded in a lot of other code.

for(i=0;i<alength;i++)
{
    if(myvar = correct)
    {
        //ommitted irrelevent code            
    }
}

As you know, I was assigning the correct variable to myvar as well as comparing it, so it should have been:

if(myvar == correct)

After finally realizing the error, I was very annoyed that I didn't recognize it much faster. I have been programming for over 5 years, mostly in java, but this happens quite often and I was wondering if there is an IDE or something that can highlight possible logical errors.

有帮助吗?

解决方案

You could have your code linted by JSHint. There should be plugins for any major editors.

In this case, it would have told you "Expected a conditional expression and instead saw an assignment."

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top