如何修复 Javascript 中缺少分号的语法错误?

发布于 2025-01-04 21:23:15 字数 409 浏览 1 评论 0原文

一位朋友为我编写了一些代码,其中有一个文件存在奇怪的语法错误。经过一番搜索后,我将范围缩小到这部分代码,它应该会重现该错误:

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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

把回忆走一遍 2025-01-11 21:23:15

您的问题是,functіion 中的 i 是 Unicode 字符 U+0456 CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I。如果您将其更改为“正常”i,它应该可以正常工作。

但现在我想知道如何破解:)你在那里得到了西里尔字符:P

EditPlus 的屏幕截图,显示突出显示的“i”,状态栏显示其代码点,0456

Your issue is the fact that the i in functіon is the Unicode character U+0456 CYRILLIC 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

Screenshot of EditPlus showing the 'i' highlighted, with the status bar showing its codepoint, 0456

迷荒 2025-01-11 21:23:15

您拼错了“函数”:)

var say = function(message){
    alert(message);
    return message;
};

say(say("Goodbye!"));

您已插入 function :)

You have misspelled the "function" :)

var say = function(message){
    alert(message);
    return message;
};

say(say("Goodbye!"));

You have inserted functіon :)

温柔少女心 2025-01-11 21:23:15

我已将其复制并粘贴到我的记事本++中,您的代码如下所示。重新输入您的 function 关键字,i 被替换为 ?。

var say = funct?on(message) {
  alert(message);
  return message;
};
say(say("Goodbye!"));

I've copied and pasted it in my notepad++ and your code look like this. Retype your function keyword, i is replaced by ?.

var say = funct?on(message) {
  alert(message);
  return message;
};
say(say("Goodbye!"));
灵芸 2025-01-11 21:23:15

我将你的代码复制到 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.

染墨丶若流云 2025-01-11 21:23:15

使用此页面验证: 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.

enter image description here

吝吻 2025-01-11 21:23:15

事实上,您插入了西里尔字母“i”而不是普通的“i”。
我在 VSCode 中收到了其他错误:

  • ',' 是预期的。 (1, 29)
  • ',' 预期。 (2, 10)
  • 预期的声明或陈述。 (4, 3)

您也可以尝试评估 "functіion" === "function"

console.log("functіon" === "function")

然而,当我尝试通过自己绘制“函数”来比较它时,它返回 true:

console.log("function" === "function")

另外,我在这里没有包含分号;在 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:

console.log("functіon" === "function")

However, when I try to compare it by drawing "function" myself, it returns true:

console.log("function" === "function")

Also, I didn't include semicolons here; in javascript they aren't necessary.

梦与时光遇 2025-01-11 21:23:15

我在调试别人的工作时遇到了类似的问题和相同的错误代码。为了解决这个问题,我将代码部分粘贴到记事本中,然后将其重新复制回 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.

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