我們的志工尚未將本文翻譯為 正體中文 (繁體) 版本。加入我們,幫忙翻譯!
您也可以閱讀本文的 English (US) 版本。

Message

SyntaxError: missing ) after condition

Error type

SyntaxError

What went wrong?

There is an error with how an if condition is written. In any programming language, code needs to make decisions and carry out actions accordingly depending on different inputs. The if statement executes a statement if a specified condition is truthy. In JavaScript, this condition must appear in parenthesis after the if keyword, like this:

if (condition) {
  // do something if the condition is true
}

Examples

It might just be an oversight, carefully check all you parenthesis in your code.

if (3 > Math.PI {
  console.log("wait what?");
}

// SyntaxError: missing ) after condition

To fix this code, you would need to add a parenthesis that closes the condition.

if (3 > Math.PI) {
  console.log("wait what?");
}

If you are coming from another programming language, it is also easy to add keywords that don't mean the same or have no meaning at all in JavaScript.

if (done is true) {
 console.log("we are done!");
}

// SyntaxError: missing ) after condition

Instead you need to use a correct comparison operator. For example:

if (done === true) {
 console.log("we are done!");
}

See also

文件標籤與貢獻者

 此頁面的貢獻者: fscholz
 最近更新: fscholz,