JavaScript error (Uncaught SyntaxError: Unexpected end of input)

850,241

Solution 1

Add a second });.

When properly indented, your code reads

$(function() {
    $("#mewlyDiagnosed").hover(function() {
        $("#mewlyDiagnosed").animate({'height': '237px', 'top': "-75px"});
    }, function() {
        $("#mewlyDiagnosed").animate({'height': '162px', 'top': "0px"});
    });
MISSING!

You never closed the outer $(function() {.

Solution 2

In my case, I was trying to parse an empty JSON:

JSON.parse(stringifiedJSON);

In other words, what happened was the following:

JSON.parse("");

Solution 3

http://jsbeautifier.org/ is helpful to indent your minified JS code.

Also, with Google Chrome you can use "pretty print". See the example screenshot below showing jquery.min.js from Stack Overflow nicely indented right from my browser :)

enter image description here

Solution 4

Formatting your code a bit, you have only closed the inner hover function. You have not closed the outer parts, marked below:

$(// missing closing)
 function() { // missing closing }
     $("#mewlyDiagnosed").hover(
        function() {
            $("#mewlyDiagnosed").animate({'height': '237px', 'top': "-75px"});
        }, 
        function() {
            $("#mewlyDiagnosed").animate({'height': '162px', 'top': "0px"});
        });

Solution 5

In my case, it was caused by a missing (0) in javascript:void(0) in an anchor.

Share:
850,241

Related videos on Youtube

Phillip
Author by

Phillip

Updated on October 14, 2020

Comments

  • Phillip
    Phillip about 3 years

    I have some JavaScript code that works in FireFox but not in Chrome or IE.

    In the Chrome JS Console I get the follow error:

    "Uncaught SyntaxError: Unexpected end of input".

    The JavaScript code I am using is:

    <script>
     $(function() {
     $("#mewlyDiagnosed").hover(function() {
        $("#mewlyDiagnosed").animate({'height': '237px', 'top': "-75px"});
     }, function() {
        $("#mewlyDiagnosed").animate({'height': '162px', 'top': "0px"});
     });
    </script>
    

    It says the error is on the last line which is });

    • Eric D. Johnson
      Eric D. Johnson about 9 years
      I know that Chrome's V8, for a DELETE on the server if the response was a 200 success instead of a 204 success - no response I would get this error as well. Just heads up in case anyone is getting this as well.
  • SLaks
    SLaks about 13 years
    The lesson is, always indent your code (and indent it correctly).
  • Sławomir Lenart
    Sławomir Lenart about 9 years
    The lesson is, always use good editor with good plugins, which can detect parentheses pairing, highlight it or even repair problems.
  • Nathan Long
    Nathan Long almost 9 years
    @HeyWatchThis You might try Syntastic for Vim.
  • trusktr
    trusktr over 8 years
    I use neomake for vim/neovim, configured to run jshint every time I save a JavaScript file. If I have syntax errors, I'll see warning/error symbols in vim's/neovim's gutter. When I put my cursor on that line, the vim/neovim command line will show a message saying what the error is.
  • mflodin
    mflodin over 8 years
    I had a // comment in my js, which commented out a bit more than I wanted since pasting it into the url of the bookmarklet made the whole code a one-liner and the // was in the middle of the code.
  • Zach Smith
    Zach Smith almost 8 years
    missing that simple }); just saved me 1 hour of debugging. many thanks @SLaks
  • taiji123
    taiji123 over 5 years
    Wonder how it could have possibly "worked in Firefox"... :-/
  • Geoffroy CALA
    Geoffroy CALA over 5 years
    I wish Javascript would use python indentation instead of punctuation...
  • Saghachi
    Saghachi about 3 years
    I had the same issue, sometimes ftp transfer mess up file's lines, and single line comments may include afterward lines in their line
  • user1210923
    user1210923 almost 2 years
    I am getting this error on the second and sunsequent calls. The first call works fine but thereafter i get the error and it points to line one of the html. Unhelpful. I wrote a program to check all brces, brackets and quotes and all are balanced. The code is quite complex maybe - and there is a lot of it. Any other ideas please?

Related