1.typeof operator: used to detect the data type of a given variable
var message="some string";
alert(typeof message); //"string"
alert(typeof(message)); //"string"
alert(typeof 100); //"number"
The typeof operator may return the following strings:
"undefined","boolean","string","number","object","function".
2. Properties and methods that instances of Object have:
constructor - saves the function used to create the current object.
hasOwnProperty("property name") - detects whether the given property is Properties of the current object instance (rather than in the prototype of the instance).
isPrototypeOf(object name) - detects whether the incoming object is the prototype of another object
toString() - returns the string representation of the object
valueof() - Returns different original values according to different objects, usually the same result returned by toString
3. Operator
! Logical NOT
The operand is an object, return false
The operand is an empty string, return true
The operand is a non-empty string, return false
The operand is a value 0, Return true
The operand is any non-zero character (including Infinty), return false
The operand is null, return true
The operand is NaN, return true
The operand is undefined, return true
* Multiplication
one operand is NaN, the result is NaN
Infinity * 0 = NaN
Infinity * non-0 = Infinity or -Infinity
Infinity * Infinity = Infinity
/ Division
0/0 = NaN
Not 0/0 = Infinity or -Infinity
==: equal ===: congruent
Equal: first convert to values of the same type before comparing
Congruent: They must be of the same type and have equal values
4. Type detection
Basic types use valueOf
var s ="ILoveYou";
var b = true;
var i = 10;
var u;
var n = null;
var o = new Object();
alert(typeof s); //string
alert(typeof i); //number
alert(typeof b); //boolean
alert(typeof u); //undefined
alert(typeof n); //object
alert(typeof o); //object
reference type Use instanceof (return true or false)
alert(person instanceof Object); // Is the variable person an Object?
alert(colors instanceof Arrary); //Is the variable colors Array?
alert(parttern instanceof Regexp); // Is parttern a Regexp?