Reference vs Syntax Error
JavaScript
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 examplesif (x === 5 { // Missing closing parenthesis console.log("Hello");let const = 5; // Using reserved keyword as variableReference 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 examplesconsole.log(undefinedVariable); // Variable doesn't existfunction test() { let x = 5;}console.log(x); // x is not accessible outside the functionnonExistentFunction(); // Function doesn't exist