Spot Missing 返回
找错误 简单
题目
这个函数返回 undefined 相反的 总和. 什么是 错误?
代码
const add = (a, b) => {
a + b;
};
console.log(add(2, 3));
提示
Arrow 函数使用 curly braces 需要 explicit 返回.
解释
When an arrow function uses curly braces { }, it has a block body and requires an explicit return statement. Without return, the function returns undefined. The fix is const add = (a, b) => { return a + b; }; or simply const add = (a, b) => a + b; (expression body without braces).
相关资源
相关课程
- JavaScript 函数
学习关于 arrow 函数返回语义.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。