Skip to content
New issue

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

73.检测数据类型的方式 #73

Open
wqjiao opened this issue Feb 26, 2021 · 0 comments
Open

73.检测数据类型的方式 #73

wqjiao opened this issue Feb 26, 2021 · 0 comments

Comments

@wqjiao
Copy link
Owner

wqjiao commented Feb 26, 2021

typeof

针对基本数据类型有效,比如:string number boolean symbol undefined,但是对于引用类型无效

typeof '' // string
typeof [] // object

instanceof

用来判断某数据值是否为 某某 的实例,返回 Boolean 值,检测的是原型

[] instanceof Array // true

constructor

''.constructor == String
new Function().constructor == Function

Object.prototype.toString.call

用来返回某个数据值类型

Object.prototype.toString.call('') // "[object String]"
Object.prototype.toString.call('').slice(8, -1) // String
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant