1.概念
分为5种基本数据类型(Null类型,Undefined类型,Boolean类型,Number类型,String类型)和复杂数据类型(Object类型)
Null类型的值是null
Undefined类型的值是undefined
Boolean类型的值是true/false
Number类型的值是数字
String类型的值是字符串
2.注意
1. Undefined、Null、Boolean、Number、String是javascript中的基本数据类型,而Object属于引用类型。用typeof检测其他类型会返回相应的字符串,但是检测null或对象时,
会返回”object"
2.typeof只是一个运算符,不能作为数据类型划分的依据,function 用typeof 返回的是function null/数组/对象 用typeof返回的是object
3.例子
var a;
var b = null;
var c = 1;
var d = "1";
var e = {"name":"1"};
var f = [1];
var g = true;
console.log(typeof a);--undefined
console.log(typeof b);--object
console.log(typeof c);--number
console.log(typeof d);--string
console.log(typeof e);--object
console.log(typeof f);--object
console.log(typeof g);--boolean
console.log(typeof test);--function
var b = null;
var c = 1;
var d = "1";
var e = {"name":"1"};
var f = [1];
var g = true;
console.log(typeof a);--undefined
console.log(typeof b);--object
console.log(typeof c);--number
console.log(typeof d);--string
console.log(typeof e);--object
console.log(typeof f);--object
console.log(typeof g);--boolean
console.log(typeof test);--function