Peter Olson
Peter Olson

Reputation: 142939

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 ';'. 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?

Upvotes: 83

Views: 95760

Answers (7)

The Alpha
The Alpha

Reputation: 146201

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

Upvotes: 11

goblin01
goblin01

Reputation: 101

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.

Upvotes: 4

PeeHaa
PeeHaa

Reputation: 72672

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

Upvotes: 137

Wernfried Domscheit
Wernfried Domscheit

Reputation: 59476

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

It displays information of each character.

enter image description here

Upvotes: 4

Sturb
Sturb

Reputation: 81

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.

Upvotes: 2

tftd
tftd

Reputation: 17042

You have misspelled the "function" :)

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

say(say("Goodbye!"));

You have inserted functіon :)

Upvotes: 18

gen_Eric
gen_Eric

Reputation: 227270

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.

Upvotes: 8

Related Questions