Syntax Error vs TypeError vs ReferenceError in JS (short note)
1 min readOct 12, 2022
SyntaxError
code : const a;Error : SyntaxError: missing = in const declarationReason : when creating a variable using const keyword, variable should be declared and assigned a value on the same line. Therefore, this error is fired because it is violating its syntax.
TypeError
code : const a = 1;
a = 2;
Error : TypeError: invalid assignment to const 'a'.Reason : keyword type const does not allow reassign value. Due to this violation a type error is fired.
ReferenceError
code : console.log(x)Error : ReferenceError: x is not defined.Reason : x is not created in the memory,and cannot be referred because it was not defined. Due to this violation a reference error is fired.code : console.log(a)
const a = 1
Error : ReferenceError: a is not defined.Reason : a is created in the memory, but cannot be referred to because it is in temporal dead zone. Due to this violation a reference error is fired.