Unexpected end of input
JavaScript Programming Language
Severity: CriticalWhat Does This Error Mean?
This error means JavaScript reached the end of your code file while still expecting more. It was in the middle of reading a function, object, string, or block — and then the file just ended. This almost always means you have a missing closing bracket, brace, or parenthesis somewhere.
Affected Models
- All browsers
- Node.js
- Deno
- Any JavaScript runtime
Common Causes
- A missing closing curly brace } at the end of a function or block
- A string that was opened with a quote but never closed
- An incomplete if statement, function, or object definition
- Accidentally deleting part of the code without realizing it
- A JSON string passed to JSON.parse() that is cut off or incomplete
How to Fix It
-
Scroll to the very end of your JavaScript file. The most common cause is a missing closing } brace for a function or block.
Every function and if/for/while block that opens with { must close with }. Check the last few lines of your file.
-
Count your opening and closing brackets throughout the file. Every { needs a }, every ( needs a ), every [ needs a ].
In VS Code, click on a bracket and it will highlight the matching one. If a bracket has no match, it will be underlined in red.
-
Check for an unclosed string. If a string starts with a quote but never ends, JavaScript reads to the end of the file looking for the closing quote.
Look for any line with an odd number of quote characters. A line like: let name = 'Alice; is missing the closing quote.
-
If the error is in JSON data (when using JSON.parse()), check if the JSON string is complete and not cut off.
Paste the JSON into jsonlint.com to validate it. The validator will show exactly where the problem is.
-
Use a code editor with bracket matching and syntax highlighting. VS Code will immediately show you unmatched brackets with red underlines.
The 'Bracket Pair Colorizer' extension for VS Code makes matching brackets very easy to see at a glance.
When to Call a Professional
This error is always fixable by the developer. It means the code file is structurally incomplete. No professional help is required — the fix is to find and add the missing closing character.
Frequently Asked Questions
Why does the error say 'end of input' when the file is not empty?
It means JavaScript ran out of file while still expecting more characters to complete a structure. For example, if you have an unclosed function — function doThing() { — JavaScript keeps reading the entire rest of the file looking for the closing }. When it reaches the end of the file without finding it, it reports 'unexpected end of input'. The file has content, but it is structurally incomplete.
How do I quickly find a missing bracket in a large file?
In VS Code, use the keyboard shortcut Ctrl+Shift+[ to jump between matching brackets. You can also use the built-in Problems panel (Ctrl+Shift+M) which lists all errors including unmatched brackets. For very large files, searching for the function or block you think is unclosed and checking its structure manually is often fastest.
Can this error come from an external JavaScript file that was not fully downloaded?
Yes — if a JavaScript file failed to download completely (due to a slow or interrupted connection), the browser may have only part of the file. This is rare but possible. A hard refresh (Ctrl+F5) forces the browser to re-download all files and usually fixes this. If it keeps happening, there may be a server issue with that specific file.