# 箭頭函式縮寫 ※第一種寫法: 1.如果只有一個參數,x 的部分可以省略括號()。 2.如果有搭配到 return 的情況下,需要用大括號包覆 {}。 3.可適用在多行參數或單行參數上。 let num = x => {return`數字相乘等於 ${x * x}`}; console.log(num(4)); //----------------------------------------------- ※第二種寫法: 1.如果只有一個參數,x 的部分可以省略括號()。 2.如果沒搭配 return 的情況下,就不需要用到大括號包覆{}。 3.只限單行參數。 let num = x => `數字相乘等於 ${x * x}`; console.log(num(4)); //----------------------------------------------- ※第三種寫法: 1.如果沒有參數,還是要有一個空括號。 2.如果沒搭配 return 的情況下,就不需要用到大括號包覆{}。 3.${內容值}需要直接寫明。 4.只限單行參數。 let num = () => `數字相乘等於 ${9}`; console.log(num());
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up