如何修复 Javascript 中缺少分号的语法错误?
一位朋友为我编写了一些代码,其中有一个文件存在奇怪的语法错误。经过一番搜索后,我将范围缩小到这部分代码,它应该会重现该错误:
var say = functіon(message) {
alert(message);
return message;
};
say(say("Goodbye!"));
当我运行此命令时,我在 Internet Explorer 控制台中看到一个错误,显示 SCRIPT1004: Expected ';'
。我没有看到任何地方缺少分号,而且我无法想象它要我在哪里放置分号。
它在哪里期望有分号?为什么在那里期望有分号?
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 ';'
. 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您的问题是,
functіion
中的i
是 Unicode 字符 U+0456CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I
。如果您将其更改为“正常”i
,它应该可以正常工作。但现在我想知道如何破解:)你在那里得到了西里尔字符:P
Your issue is the fact that the
i
infunctіon
is the Unicode character U+0456CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I
. If you change it to a 'normal'i
it should just work.But now I'm wondering how the hack :) did you get a Cyrillic character there :P
您拼错了“函数”:)
您已插入
function
:)You have misspelled the "function" :)
You have inserted
functіon
:)我已将其复制并粘贴到我的记事本++中,您的代码如下所示。重新输入您的
function
关键字,i 被替换为 ?。I've copied and pasted it in my notepad++ and your code look like this. Retype your
function
keyword, i is replaced by ?.我将你的代码复制到 jsfiddle 中,Chrome 也给出了错误。我删除了“功能”一词,然后重新输入“功能”,效果很好。
那里一定有一些额外的字符。
I copied your code into jsfiddle, and Chrome too gives an error. I deleted the word "function", and re-typed "function", and it worked fine.
There must be some extra character there.
使用此页面验证: https://r12a.github.io /uniview/?charlist=funct%D1%96on(message)
显示每个字符的信息。
Verify with this page: https://r12a.github.io/uniview/?charlist=funct%D1%96on(message)
It displays information of each character.
事实上,您插入了西里尔字母“i”而不是普通的“i”。
我在 VSCode 中收到了其他错误:
',' 是预期的。 (1, 29)
',' 预期。 (2, 10)
预期的声明或陈述。 (4, 3)
您也可以尝试评估
"functіion" === "function"
:然而,当我尝试通过自己绘制“函数”来比较它时,它返回 true:
另外,我在这里没有包含分号;在 javascript 中它们不是必需的。
In fact, you inserted Cyrillic "i" instead of normal "i".
I get the fellow errors in VSCode:
',' expected. (1, 29)
',' expected. (2, 10)
Declaration or statement expected. (4, 3)
You can try evaluating
"functіon" === "function"
as well:However, when I try to compare it by drawing "function" myself, it returns true:
Also, I didn't include semicolons here; in javascript they aren't necessary.
我在调试别人的工作时遇到了类似的问题和相同的错误代码。为了解决这个问题,我将代码部分粘贴到记事本中,然后将其重新复制回 Visual Studio。错误消失了。我认为最初编写该代码的人一定是从其中包含一些奇怪字符的地方复制的。
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. The error went away. I think whoever wrote the code originally must have copied it from somewhere with some strange characters in it.