測試模塊上運行lint時指出的錯誤:ES6的JavaScript恆返回錯誤
module.exports = (x) => {
if (x % 2 === 0) {
return 'even';
} else if (x % 2 === 1) {
return 'odd';
} else if (x > 100) {
return 'big';
} else if (x < 0) {
return 'negative';
}
};
運行ESLint:
> yarn lint
../server/modules/my-awesome-module.js (1/0)
✖ 3:22 Expected to return a value at the end of this function consistent-return
✖ 1 error (7:35:56 PM)
error Command failed with exit code 1.
什麼是在這種情況下,正確的ES6編碼? 感謝您的反饋
如果不是的情況下'x%2 === 0','x%2 === 1','x> 100'或者'x <0'例如,當x是55.5時 - 應該返回什麼? – Ryan