πŸ”§ Error Fixes
Β· 1 min read

SyntaxError: Missing Semicolon Before Statement β€” How to Fix It


SyntaxError: missing ; before statement

JavaScript found something unexpected where it expected a semicolon or end of statement.

Fix 1: Missing comma in object/array

// ❌ Missing comma
const user = {
  name: 'Alice'
  age: 25  // SyntaxError!
};

// βœ… Add comma
const user = {
  name: 'Alice',
  age: 25,
};

Fix 2: Using reserved words as variable names

// ❌ 'class' is reserved
var class = 'math';  // SyntaxError!

// βœ… Use a different name
var className = 'math';

Fix 3: Arrow function syntax

// ❌ Missing arrow
const greet = (name) { return 'hi'; };

// βœ… Add =>
const greet = (name) => { return 'hi'; };