--- title: 'SyntaxError: missing ) after condition' slug: Web/JavaScript/Reference/Errors/Missing_parenthesis_after_condition tags: - Error - Errors - JavaScript - SyntaxError translation_of: Web/JavaScript/Reference/Errors/Missing_parenthesis_after_condition ---
JavaScript の例外 "missing ) after condition" は、 if
文の条件の書き方にエラーがあった場合に発生します。 if
キーワードの後には括弧が必要です。
SyntaxError: Expected ')' (Edge) SyntaxError: missing ) after condition (Firefox)
{{jsxref("SyntaxError")}}
if
条件の書き方にエラーがあります。どのプログラミング言語でも、コードは様々な入力に応じて決定を行い、アクションを実行する必要があります。if 文は指定した条件を満たす場合、処理を実行します。JavaScript では次のように、この条件は if
キーワードの後に括弧を付ける必要があります。
if (condition) { // do something if the condition is true }
ちょっとした見落としかもしれないので、慎重にコード内のすべての括弧をチェックしてください。
if (3 > Math.PI { console.log("wait what?"); } // SyntaxError: missing ) after condition
このコードを修正するには、条件を閉じる括弧を追加する必要があります。
if (3 > Math.PI) { console.log("wait what?"); }
is
キーワードの誤用他の言語から来た人ならば、 JavaScript で同じ意味を持たないキーワードや意味のないキーワードを追加してしまいがちです。
if (done is true) { console.log("we are done!"); } // SyntaxError: missing ) after condition
代わりに、正しい比較演算子を使うべきです。例を示します。
if (done === true) { console.log("we are done!"); }