JavaScript error (Uncaught SyntaxError: Unexpected end of input)
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 :)
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.
Related videos on Youtube
Phillip
Updated on October 14, 2020Comments
-
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 about 9 yearsI know that Chrome's V8, for a
DELETE
on the server if the response was a 200success
instead of a 204success - no response
I would get this error as well. Just heads up in case anyone is getting this as well.
-
-
SLaks about 13 yearsThe lesson is, always indent your code (and indent it correctly).
-
Sławomir Lenart about 9 yearsThe lesson is, always use good editor with good plugins, which can detect parentheses pairing, highlight it or even repair problems.
-
Nathan Long almost 9 years@HeyWatchThis You might try Syntastic for Vim.
-
trusktr over 8 yearsI 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 over 8 yearsI 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 almost 8 yearsmissing that simple }); just saved me 1 hour of debugging. many thanks @SLaks
-
taiji123 over 5 yearsWonder how it could have possibly "worked in Firefox"... :-/
-
Geoffroy CALA over 5 yearsI wish Javascript would use python indentation instead of punctuation...
-
Saghachi about 3 yearsI had the same issue, sometimes ftp transfer mess up file's lines, and single line comments may include afterward lines in their line
-
user1210923 almost 2 yearsI 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?