# DAY31 - JavaScript 58. return 中斷函式後續執行 - 承 57. 函式的觀念是,整個大括號`{}`內的 code 都會被執行。 但也有一個例外,那就是 `return` 當程式碼執行到 `return` 時,整段函式就不會向下執行了。 ``` // return let 變數篇 function calcScoreTotal(numOne, numTwo) { let myScore = numOne + numTwo; return myScore; // return 後,後面的程式碼不會被執行。 console.log("1"); console.log("2"); console.log("3"); ... } let yourcalc = calcScoreTotal(20, 40); console.log(`我的成績為:${yourcalc}`); ``` ### 執行結果: ``` // 我的成績為: 60; // 後續無執行 ``` ###### tags: `Re:0 前端工程師之路 - JavaScript - function 篇章`
×
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