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