โคด๏ธreturn

๐Ÿšง ๆ–ฝๅทฅไธญ

JS โŸฉ statement โŸฉ control flow โŸฉ jump โŸฉ 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