JavaScript Learning notes common errors and debugging

Source: Internet
Author: User

Common error One: undefined variable

Abc=23; var abc=23;

Without Var, you can implicitly create a new global variable, ABC, and strictly define variables that should use the var keyword.

Common error Two: case-sensitive

var myname= "Jim"; If (myName= = "Jim")    alert (Myname.touppercase ());

There are three errors in the above code: Jim and Jim's initials J are different, and if the keyword is written in the If,touppercase () method, the letter C should be uppercase.

Common error Three: mismatched curly braces

function MyFunction () {x=1; y=2; if (x<=y) {if(x==y) {alert ("x equals Y");}} MyFunction ();

The above code is missing the curly brace for the end of the function, and it is easy to find this error if you develop a good habit of writing a good code format.

Common error Four: mismatched parentheses

if (MyVar +)/Myothervar < Mystring.length)

The above code is missing a parenthesis after the IF

Common error Five: assignment is not equal

var mynumber=99; if (mynumber=101) {     alert ("MyNumber is 101");        } Else {  alert ("MyNumber is" +MyNumber);}

If after parentheses = = = =

Common error Six: confuse attributes and methods

var New Date (); alert (nowdate.getmonth); // the correct code is below var New Date (); alert (Nowdate.getmonth ());

GetMonth the method name with parentheses

var mystring= "Hello World"; alert (Mystring.length ()); // the correct code is below var mystring= "Hello World"; alert (mystring.length);

The Length property cannot be appended with parentheses

Common error Seven: The connection string is forgotten with the + sign

var myname= "Jim"; var mystring= "Hello"; var myotherstring= "World"; mystring=myname+ "said" +mystring+ "" Myotherstring;alert ( mystring);

"" and myotherstring a little less than a + number

JavaScript Learning notes common errors and debugging

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.