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.
javascript
// Syntax Error examplesif (x === 5 { // Missing closing parenthesisconsole.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.
javascript
// 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