Learning. Some strange features of JavaScript data types are found:
Javascript is a very flexible scripting language. In addition to the well-known weak types and weak definitions, there are also some weird features that are not quite relevant to JavaScript data types:
1. The string type in Javascript is the original type, that is, it is placed in the stack rather than in the heap, which is different from other languages.
2. null and undefine, although JavaScript defines them as equal, alert (null = undefined) try!
However, they have different meanings. undefined declares variables but never initializes or assigns values to them. Null indicates that it does not exist. If a function or method returns an object, null is returned if the object cannot be found.
3. null is also an object. It is considered a placeholder for an object. Alert (typeof null) try it!
4. Nan (not a number), indicating a non-number. However, its uniqueness is that it is not equal to itself. Alert (Nan = Nan), returns false. Therefore, we generally do not recommend using the Nan value itself, but using isnan () for determination.
5. Generally, double quotation marks (") are used to represent strings and single quotation marks (") are used to represent characters. JavaScript does not matter, so the following are the same.
VaR Ss = "blue"; var Ss = 'blue ';
6. javascrip all objects have the tostring () method, whether it is an object or a pseudo object. Because the string type is a pseudo object, there must be the tostring () method (except null)
Alert (document. tostring () try!
In fact, there are also ways to convert null to a string: forced conversion (smug)
VaR S1 = string (null );
Alert (S1 );