1. Too hasty in the design phase
2. No precedent
3. Premature standardization
1. Not suitable for developing large programs
2. Very small standard library
3. null and undefined
Null is a kind of object, which means that the object is empty; undefined is a data type, which means undefined.
typeof null; // object
typeof undefined; // undefined
The two are very easy to confuse, but the meaning is completely different.
alert(foo == null); // true
alert(foo == undefined); // true
alert(foo === null); // false
alert(foo === undefined); // true
In programming practice, null is almost useless, and it should not be designed at all.
4. Global variables are difficult to control
a = 1;
})(); // 1
5. Automatically insert a semicolon at the end of the line
For example, the following function cannot achieve the expected result at all, and the return value is not an object, but undefined.
The reason is that the interpreter automatically adds a semicolon after the return statement.
6. Plus Operator
As an operator, the + sign has two meanings. It can represent the sum of a number and a number, and it can also represent a connection between a character and a character.
alert(1+10); // 11
alert(“1″+”10”); // 110
If one operation item is a character and the other operation item is a number, the number is automatically converted to a character.
alert(1+”10″); // 110
alert(“10″+1); // 101
Such a design unnecessarily aggravates the complexity of the operation, and it is completely possible to set up a character concatenated operator.
NaN is a number, which means that it exceeds the limit of the interpreter. It has some very strange features:
NaN === NaN; //false
NaN !== NaN; //true
alert( 1 + NaN ); // NaN
Rather than designing NaN, it is better to report errors directly by the interpreter, which is conducive to simplifying the program.
8. The distinction between arrays and objects
if (arr &&
typeof arr ===’object’ &&
typeof arr.length ===’number’ &&
alert(“arr is an array”);
9. == and ===
== is used to determine whether two values are equal. When the two value types are different, automatic conversion occurs, and the result is very unintuitive.
“” == “0” // false
0 == “” // true
0 == “0” // true
false == “false” // false
false == “0” // true
false == undefined // false
false == null // false
null == undefined // true
“\t\r\n” == 0 // true
Therefore, it is recommended to use the “===” (precise judgment) comparison operator at all times.
10. Basic types of packaging objects
new String(“Hello World”);
Object types corresponding to basic data types have little effect, but cause great confusion.
alert( typeof 1234); // number
alert( typeof new Number(1234)); // object