[英]How can I put an arrow function in a console.log statement so that it prints out the return value of the arrow function
我正在學習E6+,所以請善待。
對此可能有一個非常簡單的解釋,但我無法弄清楚。 如何在 console.log 語句中放置箭頭 function 以便打印出箭頭 function 的返回值。 我嘗試了以下方法,但它們不起作用:
console.log("1. Print 100:", () => { 10 * 10; }); console.log("2. Print 100:" + () => (10 * 10)); console.log("3. Print 100:", () => 10 * 10); console.log(`4. Print 100: + ${ () => {10*10;} } `);
通過調用 function 作為立即調用 Function 表達式 (IIFE) :
console.log("1. Print 100:", (() => 10 * 10)());
如所寫,您的代碼只是嘗試打印 function 本身,而不是返回值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.