🔧 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'; };