日期:2014-05-16  浏览次数:20351 次

javascript中几种变量类型判断

?

?

Type? typeof? instance? toString
Number? var n = 1? number? false? [object Number]
 ? var n = Number(1)? number? false? [object Number]
 ? var n = new Number(1)? object? true? [object Number]
String? var s = "s"? string? false? [object String]
 ? var s = String("s")? string? false? [object String]
 ? var s = new String("s")? object? true? [object String]
Boolean? var b = ture? boolean? false? [object Boolean]
 ? var b = Boolean(true)? boolean? false? [object Boolean]
 ? var b = new Boolean(true)? object? true? [object Boolean]
null? var nu = n ull? object? false? [object global]
undefined? var u = undefined? undefined? false? [object global]
Array? var a = []? object? true? [object Array]
 ? var a = Array()? object? true? [object Array]
 ? var a = new Array()? object? true? [object Array]
RegExp var r = /^$/ function?