admin管理员组文章数量:1321070
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
1 Answer
Reset to default 11Your 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.
本文标签: javascriptFunction has inconsistent return pointsStack Overflow
版权声明:本文标题:javascript - Function has inconsistent return points - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742091490a2420294.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论