最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Function has inconsistent return points - Stack Overflow

programmeradmin3浏览0评论

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);

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);
Share Improve this question edited Mar 29, 2017 at 23:48 Gareth Jones 1,4094 gold badges20 silver badges39 bronze badges asked Jul 18, 2013 at 4:20 jackyesindjackyesind 3,37314 gold badges49 silver badges74 bronze badges 1
  • 4 When quoting an error with a line number and the code associated, it would probably be useful to indicate which line is the line in the error. – T.J. Crowder Commented Jul 18, 2013 at 4:24
Add a ment  | 

1 Answer 1

Reset to default 11

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.

发布评论

评论列表(0)

  1. 暂无评论