数据类型的分类:
基本(值)类型:
String:任意字符串
Number:任意的数字
boolean:true /false
undefined: undefined
null : null
对象(引用)类型:
Object:任意对象
Function:一种特别的对象(可以执行)
Array:一种特别的对象(数值下标,内部数据是有序的)
数据类型的判断
type of: 可以判断:undefined / 数值 / 字符串 / 布尔值 / function
不能判断null 与 object , object 与Array
instanceif : 判断对象的具体类型
=== :可以判断undefined null
typeof 返回数据类型的字符串表达
var a;
console.log(a,typeof a,typeof a==='undefined',a===undefined); //undefined 'undefined' true true
console.log(undefined==='undefined');//false
a = 4;
console.log(typeof a==='number') //true
a = 'atguigu';
console.log(typeof a==='string') //true
a = true;
console.log(typeof a==='boolean') //true
a = null;
console.log(typeof a,a===null) //'object' true
a instanceof A
a代表的意思是:实例对象
A代表的意思是:构造方法
1.undefined与null的区别
undefined代表定义为赋值,null定义并赋值了,只是值为null
2.什么时候给变量赋值为null呢
初始赋值为null,表明将要赋值为对象
最后赋值为null,让其指向的对象成为垃圾对象并回收
3.严格区分数据类型与变量类型
数据类型:基本类型,对象类型
变量的类型:变量内存值的类型
基本类型:保存的就是基本类型的数据
引用类型:保存的就是地址值