What does "SyntaxError: Unexpected token function" mean?

edited September 2017 in JavaScript Mode

I'm getting it on http://studio.sketchpad.cc with a program that does not contain the string "function".

Answers

  • Link not correct

    Show complete link of your sketch

  • Link not correct

    Works fine here.

    Show complete link of your sketch

    I'm not asking for the cause in a given program. I'm asking for the meaning. I can't even parse that error message as English. "token function" makes no sense, assuming both words are the nouns.

  • The unexpected token has the value 'function'. Probably means that you are missing a closing } somewhere. But we need to see the code (especially as you say the code doesn't contain the word 'function')

  • Works fine here.

    It's asking me to register. I'm not going to register. There's also nothing in the link to identify a particular program, is probably using cookies that we don't have.

  • The unexpected token has the value 'function'.

    Thanks. Then this error message is erroneous. There's no such token in the source.

    Probably means that you are missing a closing } somewhere.

    It runs fine in Processing 3.2.1 desktop, Java mode. JS not an option here: https://i.imgur.com/43X1B0B.png

  • There's also nothing in the link to identify a particular program

    Correct. It IDs the platform - as intended.

  • edited September 2017

    @chrisjj -- re:

    Correct. It IDs the platform - as intended.

    You will get much better feedback if you share your code, specifically (or even better, an MCVE with the same error) -- for example, pasting it here. Identifying a web hosting platform in general does not do much to help solve your specific problem.

  • edited September 2017

    Then this error message is erroneous. There's no such token in the source.

    No. There is no such token in your portion of the source -- which will be combined with things like the processing-js JavaScript library. If you left off a closing brace, your portion flows incorrectly right on into the next bit.

    A quick google of this error shows that it is encountered by many Javascript programmers across a variety of different platforms and libraries, from JQuery to Server.js. It has nothing to do with http://studio.sketchpad.cc specifically -- your confidence that identifying the platform was all that was needed was misplaced.

    As @koogs pointed out, the thing most encountering this error have in common is that they accidentally left out a closing brace on a function.

    }
    

    Sharing your code makes these simple problems easier to solve without wasting too much of everyone's time.

Sign In or Register to comment.