简体   繁体   English

Javascript未捕获的SyntaxError:意外令牌{

[英]Javascript Uncaught SyntaxError: Unexpected token {

Here is my FULL code 这是我的完整代码

function onValueChange(res) {
    If (res) {

    } 
    else {

    }
};

I got error 我有错误

Uncaught SyntaxError: Unexpected token {

on If (res) { 关于If (res) {

What is wrong? 怎么了?

There are 2 updates required in your code 您的代码中需要2个更新

  1. Update i in If to lowercase. 将If中的i更新为小写。
  2. To end function you need to add closing bracket } Also, there is no need for semicolon at the end of function. 要结束函数,您需要添加右括号}此外,函数的末尾也不需要分号。

     function onValueChange(res) { if (res) { } else { } } 

You can't end functions in javascript like that. 您不能像这样结束javascript中的函数。

Instead of 代替

end function

you have to use 你必须使用

}

And if has to be lowercase. if必须是小写的。

Full code: 完整代码:

function onValueChange(res) {
    // lowercase if
    if (res) {

    } 
    else {

    }
}
  1. if condition will be lowercase like if not If. if条件将为小写,如if则为if。
  2. ';' ';' mark is not need but it is not responsible for error. 标记不是必需的,但它对错误概不负责。

function onValueChange(res) 
{
if (res){

 }
else {

 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM