基本數(shù)據(jù)類型(簡(jiǎn)單數(shù)據(jù)類型)
- string 字符串類型
- number 數(shù)值(小數(shù)和整數(shù))
- null 空
- undefined 未定義
- boolean 布爾類型(true | false)
復(fù)雜數(shù)據(jù)類型(混合數(shù)據(jù)類型)
- Object 對(duì)象類型
- Array 數(shù)組類型
- Date 日期類型
- Boolean 布爾類型
- String 字符串對(duì)象類型
- Function 函數(shù)
- RegExp 正則表達(dá)式
- Number
- Math
如何判斷數(shù)據(jù)的數(shù)據(jù)類型
關(guān)鍵字:typeof
語(yǔ)法:typeof 變量
結(jié)論:復(fù)雜數(shù)據(jù)在使用typeof操作的時(shí)候,打印出來(lái)的結(jié)果都是object ,除了函數(shù)
console.log(typeof function(){}); //functionnull注意點(diǎn)
console.log(typeof null); //object
console.log(null instanceof Object); //false
typeof的返回值是什么類型 --- string類型
<script>
var a = 'wyq';
var b = 10;
var c = true;
var d = undefined;
var e = null;
console.log(typeof a); //string
console.log(typeof b); //number
console.log(typeof c); //boolean
console.log(typeof d); //undefined
console.log(typeof e); //object
console.log(typeof null); //object
console.log(null instanceof Object); //false
console.log(typeof function(){}); //function
console.log(typeof undefined); //undefined
</script>