假设我有一个if声明return.从效率的角度来看,我应该使用
if(A > B):
return A+1
return A-1
Run Code Online (Sandbox Code Playgroud)
要么
if(A > B):
return A+1
else:
return A-1
Run Code Online (Sandbox Code Playgroud)
在使用编译语言(C)或脚本语言(Python)时,我应该更喜欢一个还是另一个?
我使用es-lint清理代码中的错误.我遇到过这个错误:
'返回'后不必要的'其他'.(无其他收益)
} else {
Run Code Online (Sandbox Code Playgroud)
返回后我总是使用else语句.有什么我可以忽略的吗?
if (cctot <= 3 && cctot > 0) {
alert('Credit under $3.00 not allowed');
return Number.MIN_SAFE_INTEGER; // important to return 0 so we can check for these conditions for validation
} else {
cctot *= -1;
}
}
return precise(cctot);
}
module.exports = calculateCredit;
Run Code Online (Sandbox Code Playgroud)