When you use the function body version of an arrow function (with {}
), there is no implied return
. You have to specify it. When you use the concise body (no {}
), the result of the body expression is implicitly returned by the function.
So you would write that either with an explicit return
:
const f = arg => { return arg.toUpperCase(); };
// Explicit return ^^^^^^
or with a concise body:
const f = arg => arg.toUpperCase();
Examples:
const f1 = arg => { return arg.toUpperCase(); };
console.log(f1("testing"));
const f2 = arg => arg.toUpperCase();
console.log(f2("testing"));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…