Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
JavaScript の例外 "return (or yield) not in function" は、 return 文または yield 文が関数の外側で呼び出されたときに発生します。
return 文か yield 文が 関数 の外側で呼び出されました。どこかで、中括弧を忘れたのかもしれません。 return 文と yield 文は、関数内で使用しなければなりません。これらの文は、関数の実行を終了 (または、停止や再開) し、関数の呼び出し元に返す値を指定するからです。
一見すると、中括弧は正しく見えますが、このコードスニペットでは、最初の if 文の後の { を忘れています。正しくは以下のようにします。
This page was last modified on 2023年8月18日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.