Type Error Vs Reference Error

Table of contents

No heading

No headings in the article.

Introduction
In this article, we will learn about the difference between Type and reference errors.

Type Error
The error occurs when you use something that is not intended to be used.
example. Using a sharpener to erase something written in pencil.

Type error example1
Here, The variable 'a' is declared with a value of 1. The error occurred because we are calling a variable like we are calling a function.

Type error example 2
Here, we are declaring a const with a value and trying to redeclare it again.

Reference error
It is the error, that occurs when the variable doesn't exist in the current scope or doesn't initialize (declared).
Example. When you search for a thing that is not there.

Reference error example 1
In this example, we are calling a variable 'b' that is not present in the code.

Reference error example 2
In this example, The variable 'a' is declared. But, the scope of the variable is not visible outside of curly braces{}.