Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function has inconsistent return points

When running Intellij's inspections on some javascript I wrote, it reports

function 'createPages' has inconsistent return points at line 35

But I'm not sure what it means, or how to solve this issue.

The function looks like this:

function createPages(noOfCounts) {
    var default_page = 1, default_count = 15;
    if (noOfCounts != "" && noOfCounts != null) {
        if (noOfCounts > default_count) {
            try {
                var tempVal = parseInt(noOfCounts / default_count);
                jQuery("#page").val(tempVal);
                return true;
            }
            catch (e) {
                alert('Error . ' + e);
            }
        } else {
            alert("It should not be less than the 15 and should be a number");
            return false;
        }
    }
    else {
        jQuery("#page").val(default_page);
        return true;
    }
}

And is being called like so:

var valid = createPages(noOfCounts);
like image 795
jackyesind Avatar asked Oct 20 '25 09:10

jackyesind


1 Answers

Your function will (in effect) return undefined implicitly after it reaches alert('Error . ' + e);, because execution will reach the end of the function without an explicit return.

So probably making sure that all code paths through the function return a value explicitly will get rid of the IntelliJ error.

like image 194
T.J. Crowder Avatar answered Oct 22 '25 22:10

T.J. Crowder