We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
本系列的主题是 JavaScript 基础,每期讲解一个技术要点。如果你还不了解各系列内容,文末点击查看全部文章,点我跳转到文末。
如果觉得本系列不错,欢迎 Star,你的支持是我创作分享的最大动力。
typeof 能判断所有的原始类型
我们可以看出typeof能正确的判断出6种原始类型。不能用来判断null或者引用数据类型object(对象、数组和函数)。
对于原始数据类型,我们可以使用typeof()函数来判断他的数据类型:
console.log(typeof ""); console.log(typeof 1); console.log(typeof true); console.log(typeof null); console.log(typeof undefined); console.log(typeof []); console.log(typeof function(){}); console.log(typeof {});
看看控制台输出什么
可以看到,typeof对于基本数据类型判断是没有问题的,但是遇到引用数据类型(如:Array)是不起作用的。
typeof 能判断是否是函数
//typeof 能判断函数 typeof console.log(1) // function typeof function fn () {} // function
typeof 能判断出是否是引用类型(不可细分)
//typeof 判断引用类型 const a = null typeof a //object const a = { a: 100 } typeof a // object const a = ['a'] typeof a // object
查看全部文章
各系列文章汇总:https://github.com/yuanyuanbyte/Blog
我是圆圆,一名深耕于前端开发的攻城狮。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
本系列的主题是 JavaScript 基础,每期讲解一个技术要点。如果你还不了解各系列内容,文末点击查看全部文章,点我跳转到文末。
如果觉得本系列不错,欢迎 Star,你的支持是我创作分享的最大动力。
typeof 能判断哪些类型
typeof 能判断所有的原始类型
我们可以看出typeof能正确的判断出6种原始类型。不能用来判断null或者引用数据类型object(对象、数组和函数)。
对于原始数据类型,我们可以使用typeof()函数来判断他的数据类型:
看看控制台输出什么
可以看到,typeof对于基本数据类型判断是没有问题的,但是遇到引用数据类型(如:Array)是不起作用的。
typeof 能判断是否是函数
typeof 能判断出是否是引用类型(不可细分)
查看全部文章
博文系列目录
交流
各系列文章汇总:https://github.com/yuanyuanbyte/Blog
我是圆圆,一名深耕于前端开发的攻城狮。
The text was updated successfully, but these errors were encountered: