检测数据类型
typeof 檢測數據類型
typeof 返回數據類型 number string Boolean function object undefined ;
? ? ?返回object
var shuzu = [5,5,3,6,3]; console.log(typeof(shuzu));//object
返回number
var Num = 666; console.log(typeof(Num));//number
返回Boolean
var Boo = true,BOo = false; console.log(typeof(Boo),typeof(BOo)); //Boolean? ? ? 返回string
var str = "5555"; console.log(typeof(str)); //string? 返回undefined
console.log(typeof(aaa)); //aaa未定義 所以 返回 undefined返回function
var aaa = function(){console.log(555)}; console.log(typeof(aaa)) //返回function用construtor來檢測數據類型 ()
var test=new Array();//改變test 來檢測 if (test.constructor==Array) { document.write("This is an Array"); } if (test.constructor==Boolean) { document.write("This is a Boolean"); } if (test.constructor==Date) { document.write("This is a Date"); } if (test.constructor==String) { document.write("This is a String"); } if(test.constructor==Function) { document.write("This is a Function"); }?
轉載于:https://www.cnblogs.com/GreenRadish/p/11157678.html
總結
- 上一篇: Spring5 新增的两大功能,吹一波这
- 下一篇: 为了搞清楚CDN的原理,我头都秃了...