The arrow function returns the function text - "(n) => 5 + n" and not the result (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:
function newText(n) { return 5 + n; }
document.write(newText);
has the same problem.
Call the function
document.write(newText(5));
You need to call the arrow function.
let n = 1;
let newText = (n) => 5 + n;
document.write(newText(n));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.