Side-by-side comparison of ReferenceError and SyntaxError — understand the differences, causes, and fixes.
ReferenceErrorA reference was made to a variable that does not exist in the current scope.
You tried to use a variable that has not been declared, is not in scope, or was accessed before its declaration (temporal dead zone). This can also happen with misspelled variable names.
Declare the variable before using it with let, const, or var. Check for typos in variable names. Ensure the variable is in scope where you are accessing it. Import missing modules.
SyntaxErrorThe JavaScript engine encountered code that does not conform to the language syntax.
The code contains invalid syntax that the JavaScript parser cannot understand. This includes missing brackets, unmatched parentheses, invalid characters, or using language features not supported by the runtime.
Check the error message for the line and column number. Look for missing or extra brackets, parentheses, quotes, or semicolons. Use a linter like ESLint to catch syntax errors before runtime.