Skip to content

Mismatched Curly Braces

Quick summary

You have more { than } (or vice versa) — the parser cannot determine where a block ends and reports a syntax error.

Why this happens

  • Forgot a closing } after a function or object literal

  • Extra } from deleting a block but leaving its closer

  • Nested blocks where one level's closer was accidentally removed

Minimal example

✗ Broken code
function greet(name) {
  if (name) {
    return 'hi';
  // missing two closing braces
✓ Fixed code
function greet(name) {
  if (name) {
    return 'hi';
  }
}

Two closing braces are missing — one for the if block and one for the function. Adding them closes both blocks so the parser succeeds.

How to diagnose

  • Read the SyntaxError — it often says 'Unexpected token }' or 'Unexpected end of input'

  • Use the editor's bracket matching to jump from each { to its }

  • Run a formatter that will report unbalanced braces

How to fix

  • Add the missing closing brace at the correct indentation level

  • Remove the extra brace that does not open a block

  • Re-indent the file so block structure is visually obvious

How to prevent

  • Use an editor with bracket matching and auto-closing braces

  • Format on save to keep brace balance visible

Related Resources

Related Glossary

Related Lessons

← Back to language