typeof返回的数据类型有6种,分别为:1、object,对象类型;2、undefined,未定义类型;3、string,字符串类型;4、number,数字类型;5、boolean,布尔类型;6、function,函数类型。

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返回的数据类型有哪些的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号