Unexpected end of input

JavaScript ErrorSyntaxErrorCommonLast updated: June 28, 2026Tested on:V8 Engine v11.3ECMAScript 2023June 2026

The JavaScript engine reached the end of the file/string while still expecting closing characters.

Unexpected end of input Quick Fix⏱️ Est. Fix Time: 1–3 minutes

Usually happens because:

  • Missing closing brace }
  • Missing closing bracket ]
  • Incomplete JSON payload

🔍 Quick Checklist:

📊 Where this usually happens (estimated occurrence)

Missing function/class braces55%
Unclosed string/array quotes25%
Network JSON truncation20%

What is Unexpected end of input?

This error occurs when the parser reaches the very end of the file or string payload while it is still waiting for closing delimiters (like a matching curly brace, parenthesis, bracket, or quotation mark) to resolve an active block declaration.

Common Causes

  • Forgetting to close a function, loop, or class block.
  • Leaving arrays, objects, or string quotes unclosed.
  • Incomplete JSON strings passed to JSON.parse().

Common Mistakes

  • Writing long nested scripts without keeping indentation consistent, making it hard to see missing closing braces.
  • Parsing incomplete network stream chunks before they fully resolve.

How to Fix

1Review the end of the script to ensure all opened structures are terminated.
2Use an editor that highlights matching braces.
3Check for complete payloads in network requests before parsing JSON.

Framework-Specific Examples

Omitting the square bracket at the end of array lists.

Mismatched Array Closing Bracket Example
try {
  // Throws: Unexpected token ';' or end of input depending on engine
  const list = [1, 2, 3;
} catch (err) {
  // Parsing blocks code load
}

Server Configuration Examples

Checking JSON buffers.

JSON stream validation Config
# Handled at parser layer

Best Practices

  • Standardize on automatic editor brace insertion plugins.
  • Run lint formatting tools before running local servers.

Frequently Asked Questions (FAQ)

Q: What does 'end of input' mean?

It means the JavaScript engine parsed the entire file or string but reached the end of the text while still waiting for matching characters (like `}`, `]`, or `)`) to close open blocks.

Q: Why does this error point to the last line of my file?

Because the parser doesn't know you forgot a brace until it reaches the very end of the file and still hasn't found it. The missing brace could be anywhere inside the script.

Q: Can I catch this error in try-catch?

Only if it happens inside dynamic execution blocks like `eval()` or `JSON.parse()`. General syntax errors inside your source files block compilation completely, so no code runs.

Q: How do I prevent incomplete network buffers?

Verify that your API response has completed fully before executing `.json()` or parsing payload buffers.

Still having this problem?

Didn't solve your problem?

SuggestRequest Error