[英]arrow function returns the function text and not the result (javascript)
The arrow function returns the function text - "(n) => 5 + n" and not the result (6). 箭头函数返回函数文本-“(n)=> 5 + n”,而不返回结果(6)。 What am I doing wrong?
我究竟做错了什么?
let n = 1;
let newText = (n) => 5 + n;
document.write(newText);
You're not calling the function: 您没有在调用该函数:
document.write(newText(42));
This has nothing to do with =>
or let
, by the way: 顺便说
let
,这与=>
或let
无关:
function newText(n) { return 5 + n; }
document.write(newText);
has the same problem. 有同样的问题。
Call the function 调用函数
document.write(newText(5)); document.write(newText(5));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.