JavaScript debugging common errors and reasons
Test environment Chrome Version 66.0.3359.170 (official version) (64-bit)
TypeError type Error
is not a data type accepted by the operator.
//--------treat values that are not functions as function calls varFoo =undefined; Foo ();//Uncaught Typeerror:foo is not a function //Foo is not a function //--------Calling a function that does not exist in the object is actually undefined varx =Document. getElementById (' foo ');//Uncaught TypeError:document.getElementByID is not a function //The value called is not a function //--------Calling an undeclared methodLala ();//uncaught Referenceerror:lala is not defined //Lala not defined //--------treat null or undefined as an object varSomeval =NULL; Someval.foo;//uncaught Typeerror:cannot Read Property ' foo ' of NULL //cannot read the null Foo property varSomeval =undefined; Someval.foo;//uncaught Typeerror:cannot Read Property ' foo ' of undefined //Unable to read undefined Foo property
Referenceerror Reference Error
An attempt is made to assign a variable that cannot be assigned a value.
//--------attempt to assign values to variables that cannot be assigned. function dosomething() {}; DoSomething () =' Somevalue ' //uncaught referenceerror:invalid left-hand side in assignment //The left of the assignment is not valid
Rangeerror Range Error
The set value is within the range of the data type. such as the range of numbers, the range of array lengths.
[].length = -1// 数据的 length 不能小于 0 undefined// // Uncaught RangeError: Invalid array length // 无效的数组长度
SyntaxError syntax error
The code that cannot be parsed.
//-------- 拼接字符串,但是没有使用 + 号 ‘ni‘ ‘hao‘ // Uncaught SyntaxError: Unexpected string // 意料之外的字符串 //-------- 没有使用成对的引号 var str = ‘ni hao // Uncaught SyntaxError: Invalid or unexpected toke // 无效或意料之外的标记 //-------- 无效的正则 var reg = /[/ // Uncaught SyntaxError: Invalid regular expression: missing /
?
JavaScript debugging common errors and reasons