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

JavascriptUnicodeSyntax Error

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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

unicode error in js

Solution 2 - Javascript

You have misspelled the "function" :)

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

say(say("Goodbye!"));

You have inserted functіon :)

Solution 3 - Javascript

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!"));

Solution 4 - Javascript

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.

Solution 5 - Javascript

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.

Solution 6 - Javascript

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.

Solution 7 - Javascript

Verify with this page: https://r12a.github.io/uniview/?charlist=funct%D1%96on(message)

It displays information of each character.

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPeter OlsonView Question on Stackoverflow
Solution 1 - JavascriptPeeHaaView Answer on Stackoverflow
Solution 2 - JavascripttftdView Answer on Stackoverflow
Solution 3 - JavascriptThe AlphaView Answer on Stackoverflow
Solution 4 - Javascriptgen_EricView Answer on Stackoverflow
Solution 5 - Javascriptgoblin01View Answer on Stackoverflow
Solution 6 - JavascriptSturbView Answer on Stackoverflow
Solution 7 - JavascriptWernfried DomscheitView Answer on Stackoverflow