typeof 共返回6种数据格式:
1、object --对象类型的变量或值,或者null(这个是js历史遗留问题,将null作为object类型处理)
2、undefined --未定义的变量或值
3、string --字符串类型的变量或值
4、number --数字类型的变量或值
5、boolean --布尔类型的变量或值
6、function --函数类型的变量或值
示例:
undefined
var a1; typeof(a1);
运行结果:
number
var num1=12; typeof(num1);
运行结果:
string
var num2="12"; typeof(num2);
运行结果:
boolean
var flag=true; typeof(flag);
运行结果:
object
var str=new string();typeof(str);var a=null; typeof(a);
运行结果:
function
var fn = function(){};typeof(fn); typeof(class c{});
运行结果:
更多编程相关知识,请访问:编程入门!!
以上就是typeof返回的数据类型有哪些的详细内容。
