繁体   English   中英

箭头函数返回函数文本而不是结果(javascript)

[英]arrow function returns the function text and not the result (javascript)

箭头函数返回函数文本-“(n)=> 5 + n”,而不返回结果(6)。 我究竟做错了什么?

let n = 1;
let newText = (n) => 5 + n;
document.write(newText);

您没有在调用该函数:

document.write(newText(42));

顺便说let ,这与=>let无关:

function newText(n) { return 5 + n; }
document.write(newText);

有同样的问题。

调用函数

document.write(newText(5));

您需要调用箭头功能。

JS小提琴

let n = 1;
let newText = (n) => 5 + n;
document.write(newText(n));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM