Skip to content

Invalid Arrow Function Syntax

Quick summary

Your arrow function has malformed parameters or a body that does not parse — the compiler rejects the file.

Why this happens

  • Omitting the arrow => between parameters and body

  • Using a statement block without braces, or braces without a return for an expression

  • Rest parameters in an invalid position or default params with wrong syntax

Minimal example

✗ Broken code
const add = (a, b) a + b; // SyntaxError: Unexpected token
console.log(add(1, 2));
✓ Fixed code
const add = (a, b) => a + b; // arrow added
console.log(add(1, 2)); // 3

The => arrow is missing between the parameters and the body, so the parser cannot recognize the arrow function. Adding => makes it valid.

How to diagnose

  • Read the SyntaxError and locate the arrow function in the reported line

  • Verify the parameter list is wrapped in parentheses when there is more than one param

  • Check that the body uses either an expression or a braced block, not a mix

How to fix

  • Add the => arrow between the parameter list and the body

  • Wrap multi-statement bodies in { } and add return if a value is needed

  • Use parentheses around a single param for consistency and clarity

How to prevent

  • Use a formatter (Prettier) that normalizes arrow function syntax

  • Run the compiler/linter on save to catch syntax errors immediately

Related Resources

Related Glossary

Related Lessons

← Back to language