js基础==基本数据类型,引用数据类型

157 阅读1分钟

js基础==基本数据类型,引用数据类型 检测数据类型

一、基本数据类型

Number,String,Boolean,Undefined,Null

二、引用数据类型

对象Object,数组Array,function,正则,日期,Math

三、检测数据类型
//1、tyoeof
		console.log(typeof 8); //number
        console.log(typeof '字符串'); //string
        console.log(typeof false); //boolean
        console.log(typeof null); //object==========涉及到面试
        console.log(typeof undefined); //undefind==========涉及到面试


//2、instanceof
  		var t = [8, 8]
  		// t 部分是需要检测的数据   Array是需要检测t是否是这个类型数据,是返回true,不是返回false,其他可自行敲代码查看现象
        console.log(t instanceof Array); //------true
   		//*注意:intanceof“‘不能’”检测基本数据类型



//3、Object.prototype.toString.call()
		console.log(Object.prototype.toString.call(8));//=======打印[object Number]
		//可以检测任意数据类型,括号内的内容为需要检测的数据  其他数据可自行检测

本人常用,其他可再做拓展

一定要落实到键盘,不要光用笔头记呦!!!!!!