SyntaxError: missing ) after condition - JavaScript 编辑

The JavaScript exception "missing ) after condition" occurs when there is an error with how an if condition is written. It must appear in parenthesis after the if keyword.

Message

SyntaxError: Expected ')' (Edge)
SyntaxError: missing ) after condition (Firefox)

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

Missing parenthesis

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?");
}

Misused is keyword

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:75 次

字数:3312

最后编辑:7 年前

编辑次数:0 次

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文