Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference TypeError and ReferenceError

What's the differnce between

TypeError: ... is undefined

and

ReferenceError: ... is not defined

?

like image 418
Evgenij Reznik Avatar asked Sep 25 '12 18:09

Evgenij Reznik


1 Answers

A ReferenceError occurs when you try to use a variable that doesn't exist at all.

A TypeError occurs when the variable exists, but the operation you're trying to perform is not appropriate for the type of value it contains. In the case where the detailed message says "is not defined", this can occur if you have a variable whose value is the special undefined value, and you try to access a property of it.

See http://javascriptweblog.wordpress.com/2010/08/16/understanding-undefined-and-preventing-referenceerrors/ for some discussion related to this.

like image 191
Barmar Avatar answered Nov 26 '22 05:11

Barmar