⤴️return

🚧 施工中

JSstatementcontrol flowjump ⟩ return

(statement)

end execution and return a value to the caller. undefined is returned if expr omitted.

return <expr>

return statement can be used only within the body of a function, using it anywhere else causes a SyntaxError.

return is affected by automatic semicolon insertion

⚠️ 注意:用 return 時,不要寫成這樣:

return
    a + b;

這種寫法 return 後面會被自動加上 ";" 分號

return;        // 自動加上「;」分號❗️ 
a + b;

建議寫成這樣:

return (
    a + b
);

Last updated