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

前端 未结 6 1982
说谎
说谎 2020-12-08 02:24

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 rep

相关标签:
6条回答
  • 2020-12-08 02:52

    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

    0 讨论(0)
  • 2020-12-08 02:52

    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.

    0 讨论(0)
  • 2020-12-08 02:57

    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.

    0 讨论(0)
  • 2020-12-08 02:58

    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!"));
    
    0 讨论(0)
  • 2020-12-08 03:02

    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.

    0 讨论(0)
  • 2020-12-08 03:10

    You have misspelled the "function" :)

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

    You have inserted functіon :)

    0 讨论(0)
提交回复
热议问题