1. typeof OPERATOR: used to detect the Data Type of a given variable. 1 varmessage & quot; somestring & quot; 2 alert (typeofmessage); // & quot; string & quot; 3 alert (typeof (message); // & quot; string & quot; 4 alert (typeof10
1. typeof OPERATOR: used to detect the Data Type of a given variable
1 var message = "some string ";
2 alert (typeof message); // "string"
3 alert (typeof (message); // "string"
4 alert (typeof 100); // The "number" typeof operator may return the following string:
"Undefined", "boolean", "string", "number", "object", "function ".
2. attributes and methods of the Object instance:
Constructor -- save the function used to create the current object.
HasOwnProperty ("property name") -- checks whether a given property is the property of the current object instance (instead of in the instance prototype ).
IsPrototypeOf (Object Name) -- checks whether the input object is a prototype of another object.
ToString () -- returns the string representation of the object
Valueof () -- return different original values based on different objects. It is usually the same as the return result of toString.
3. Operators
! Non-logical
Returns false if the operand is an object.
Returns true if the operand is an empty string.
Returns false if the operand is a non-null string.
Returns true if the operand is 0.
The operand is a non-zero arbitrary character (including Infinty), and false is returned.
Returns true if the operand is null.
Returns true if the operand is NaN.
Returns true if the operand is undefined.
* Multiplication
An operand is NaN and the result is NaN.
Infinity * 0 = NaN
Infinity * Non-0 = Infinity or-Infinity
Infinity * Infinity = Infinity
/Division
0/0 = NaN
Non-0/0 = Infinity or-Infinity
==: Equal
Equal: first convert to a value of the same type for comparison
Full: It must be of the same type and have the same value.
4. Type Detection
ValueOf for Basic Types
1 var s = "ILoveYou ";
2 var B = true;
3 var I = 10;
4 var u;
5 var n = null;
6 var o = new Object ();
7 alert (typeof s); // string
8 alert (typeof I); // number
9 alert (typeof B); // boolean
10 alert (typeof u); // undefined
11 alert (typeof n); // object
12 alert (typeof o); // object
Instanceof for reference type (return true or false)
1 alert (person instanceof Object); // is the variable "person" an Object?
2 alert (colors instanceof Arrary); // is the variable colors Array?
3 alert (parttern instanceof Regexp); // is parttern Regexp?
From Sunday walk