Home >Web Front-end >JS Tutorial >Javascript Study Notes 1 Data Type_Basic Knowledge
There is only one form of code type and that is function.
undefined: Undefined, we can also call it non-existent, typeof(undefined)=undefined.
null: Empty. Undefined means it does not exist, and null means it exists, but is absent. typeof(null)=object, but null is not object. This is the magical and unique thing about null.
boolean: true or false.
Number: NaN and Infinity are two special numbers. NaN represents a number that cannot be expressed numerically, while Infinity represents an infinite number. On the contrary, -Infinify represents negative infinity. There are two special things here: NaN!=NaN, Infinity/Infinity=NaN. In the Number type, there is a very useful method: ToString(), which can accept a number from 2 to 36, and then convert our Number into the corresponding base number.
String: String. There is no concept of characters in Javascript. String is the smallest unit to represent text. In strings, there are two functions, charAt(index) and charCodeAt(index), which return the character corresponding to the index and the character Unicode encoding respectively. In our daily life, we may often use subscripts to access, such as s[10], but this is not an ECMAScript standard and should be avoided as much as possible.
All types of Javascript are built based on these five simple types. There are countless complex relationships between these five types. Undefined, null, 0, "" are false when converted to boolean, and except for these four, all are true. But among these five, except for undefined==null, the others are not equal.
Here we have another incompatibility with strongly typed languages, such as 123=="123". So how can we differentiate between types? At this time: all equal to: === comes into use.