typeof
console.log(typeof coke)//coke為變量,var coke=123;
從輸出的結(jié)果來(lái)看,arr, json, nul, date, reg, error 全部被檢測(cè)為object類型,其他的變量能夠被正確檢測(cè)出來(lái)。當(dāng)需要變量是否是number, string, boolean, function, undefined, json類型時(shí),可以使用typeof進(jìn)行判斷。其他變量是判斷不出類型的,包括null。還有,typeof是區(qū)分不出array和json類型的。因?yàn)槭褂胻ypeof這個(gè)變量時(shí),array和json類型輸出的都是object。