JavaScript debugging common errors and reasons

Source: Internet
Author: User
Tags array length

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.