0

What does this error means?

Return statement is inconsistent with previous usage

Netbeans show this error when i coded the below (snippet):

$.each(ToValidate, function (indexOfQuestions, questionNumber) {
    var radioValue = "ja";

    if (radioValue === "NEI" && questionNumber === "1.1") {
        return false;
    } else if (radioValue === "JA" && questionNumber === "1.1") {
        return;
    }
});

in else if, I am trying to continue the each, so I am using return. In if I need to break the control out of each so I am using return false. But that error is quite confusing.

Have I used keywords correctly or is there any other way to use Continue and Break in JQuery?

fatherazrael
  • 5,511
  • 16
  • 71
  • 155
  • 1
    It probably means your editor thinks it makes more sense to return `true` and not just `undefined`, which I tend to agree with. – adeneo May 12 '15 at 05:12
  • `return;` is the JavaScript equivalent of "return nothing from a void function" (it actually returns undefined implicitly). It's not actually an *error*, but a *warning* - specify the return value explicitly (is it really supposed to be undefined?) to avoid it. – user2864740 May 12 '15 at 05:13
  • Also note that the `else` clause is totally useless in that code, it will just return anyway ? – adeneo May 12 '15 at 05:14
  • possible duplicate of [Is there a benefit to using a return statement that returns nothing?](http://stackoverflow.com/questions/3717420/is-there-a-benefit-to-using-a-return-statement-that-returns-nothing) – Rahul Tripathi May 12 '15 at 05:15

2 Answers2

2

The answer is documented in NetBeans wiki: link.

What this means is that a caller of the function can't expect a single type of return value which complicates using the function.

Having said that, in the current context that is completely valid code, since $.each only cares if the return value is false.

Amit
  • 45,440
  • 9
  • 78
  • 110
0

This is a code checking function noticing that you're returning a value in one code path and not returning a value in another code path in the same function. Usually, you either want to return a value or not return a value from a given function, not sometimes one and sometimes the other.

So, it is warning you about that unusual (and likely wrong) condition.

jfriend00
  • 683,504
  • 96
  • 985
  • 979