How do I fix this missing semicolon syntax error in Javascript?

放肆的年华 提交于 2019-11-28 04:50:49

Your issue is the fact that the i in function is the unicode character i. If you change it to a 'normal' i it should just work.

But now I'm wondering how the hack :) did you get an unicode character there :P

tftd

You have misspelled the "function" :)

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

say(say("Goodbye!"));

You have inserted 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 ?.

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

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.

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.

In fact, you inserted unicode "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:

function compare() {
  return "functіon" === "function"
}
console.log(compare())

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

function compare2() {
  return "function" == "function"
}
console.log(compare2())

Also, I didn't include semicolons here, in javascript they aren't necessary.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!