What is the difference
TypeError: ... is undefined
and
ReferenceError: ... is not defined
?
A ReferenceErroroccurs when you try to use a variable that does not exist at all.
ReferenceError
A TypeErroroccurs when a variable exists, but the operation you are trying to perform is not suitable for the type of value it contains. In the case where the detailed message says "not defined", this can happen if you have a variable whose value is a special value undefinedand you are trying to access its property.
TypeError
undefined
. http://javascriptweblog.wordpress.com/2010/08/16/understanding-undefined-and-preventing-referenceerrors/ , .
JavaScript:
JavaScript 1.5 :
EvalError: , eval() .
RangeError: , .
ReferenceError: , .
SyntaxError: , JavaScript.
TypeError: , .
strong text URIError: , encodeURI() decodeURI() .
encodeURI()
decodeURI()
:
function foo(){ var d=1234; console.log(d.substring(1,2)); } foo();
: TypeError: d.substring , () (, ). TypeError , .
function foo(){ var d=1234; console.log(c); } foo();
: ReferenceError: c , "c" , , . ReferenceError , .