Table of contents
What is Type Error?
A Type error is caused when :
an operand or argument passed to a function is incompatible with the type expected
modified a value that cannot be changed.
trying to use the value that can't be used.
There is a variable named const if we try to change the value for it it will throw a type error.
const a = 20;
a = 10;
In the above example, trying to change the value of the const variable throws a type error.
What is Reference Error?
A Reference error is caused when :
- a variable that doesn't exist in the current scope is referenced.
When you create a variable, all you are doing is creating a reference with a value. var a = 20
tells the JS compiler that any time it sees the variable a
, it is seeing a number with a value of 20
.
console.log(a);
let a = 20;
In the above example, we are trying to access the variable a
before declaring it, so the javascript engine is not able to get a reference for that hence it throws a reference error.
Thank you for reading! Hope you liked it and learned something from it.