[英]How do I fix this missing semicolon syntax error in Javascript?
A friend wrote some code for me, and there was one file with a weird syntax error in it.一位朋友为我写了一些代码,其中有一个文件有一个奇怪的语法错误。 After a bit of hunting, I narrowed it down to this section of code, which should reproduce the error:
经过一番搜索,我将范围缩小到这部分代码,它应该会重现错误:
var say = functіon(message) {
alert(message);
return message;
};
say(say("Goodbye!"));
When I run this, I see an error in the Internet Explorer console that says SCRIPT1004: Expected ';'
当我运行它时,我在 Internet Explorer 控制台中看到一个错误,显示
SCRIPT1004: Expected ';'
. . I don't see a semicolon missing anywhere, and I can't imagine where it wants me to put one.
我没有看到任何地方缺少分号,而且我无法想象它想让我把分号放在哪里。
Where does it expect a semicolon and why does it expect a semicolon there?它在哪里期望分号,为什么在那里期望分号?
Your issue is the fact that the i
in function is the unicode character i
.您的问题是
i
in 函数是unicode字符i
。 If you change it to a 'normal' i
it should just work.如果您将其更改为“正常”
i
它应该可以正常工作。
But now I'm wondering how the hack :) did you get an unicode character there :P但现在我想知道如何破解:) 你在那里得到了一个 unicode 字符:P
You have misspelled the "function" :)您拼错了“功能”:)
var say = function(message){
alert(message);
return message;
};
say(say("Goodbye!"));
You have inserted functіon
:)您已插入
functіon
:)
I've copied and pasted it in my notepad++ and your code look like this in my notepad++, retype your function keyword, i is replaced by ?.我已经将它复制并粘贴到我的记事本 ++ 中,您的代码在我的记事本 ++ 中看起来像这样,重新键入您的函数关键字,i 被替换为 ?。
var say = funct?on(message) {
alert(message);
return message;
};
say(say("Goodbye!"));
I copied your code into jsfiddle, and Chrome too gives an error.我将您的代码复制到 jsfiddle 中,Chrome 也出现错误。 I deleted the word "function", and re-typed "function", and it worked fine.
我删除了“函数”这个词,并重新输入了“函数”,效果很好。
There must be some extra character there.那里一定有一些额外的字符。
In fact, you inserted unicode "i" instead of normal "i".实际上,您插入了 unicode“i”而不是普通的“i”。 I get the fellow errors in VSCode:
我在 VSCode 中遇到了其他错误:
',' expected. (1, 29)
',' expected. (2, 10)
Declaration or statement expected. (4, 3)
You can try evaluating "functіon" == "function"
as well:您也可以尝试评估
"functіon" == "function"
:
function compare() { return "functіon" === "function" } console.log(compare())
function compare2() { return "function" === "function" } console.log(compare2())
I had a similar problem and the same error code when debugging someone else's work.在调试其他人的工作时,我遇到了类似的问题和相同的错误代码。 To fix this I pasted the section of code into Notepad and then re-copied it back to Visual Studio.
为了解决这个问题,我将代码部分粘贴到记事本中,然后将其重新复制回 Visual Studio。 The error went away.
错误消失了。 I think whoever wrote the code originally must have copied it from somewhere with some strange characters in it.
我认为最初编写代码的人一定是从某个带有一些奇怪字符的地方复制了它。
Verify with this page:https://r12a.github.io/uniview/?charlist=funct%D1%96on(message)验证此页面:https ://r12a.github.io/uniview/?charlist=funct%D1%96on(message)
It displays information of each character.它显示每个字符的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.