Reference vs Syntax Error

JavaScriptDEShaw

Syntax Error

A syntax error occurs when you write code that violates JavaScript's language rules - essentially invalid code that can't be parsed. The code won't even run.

// Syntax Error examples
if (x === 5 { // Missing closing parenthesis
console.log("Hello");

let const = 5; // Using reserved keyword as variable

Reference Error

A reference error occurs when you try to use or access a variable or function that doesn't exist or is out of scope. The code is valid JavaScript syntax, but refers to something undefined.

// Reference Error examples
console.log(undefinedVariable); // Variable doesn't exist

function test() {
let x = 5;
}
console.log(x); // x is not accessible outside the function

nonExistentFunction(); // Function doesn't exist

Resources

00:00