当前位置:网站首页>JS notes data type judgment
JS notes data type judgment
2022-04-21 23:36:00 【Yunhu doesn't like it?】
I came across an article today typeof and instanceof The difference between , At the end of the article
console.log(Number instanceof Number);//false console.log(String instanceof String);//false
It's a bit of a mystery , I was thinking Number and String Why not instanceof What about themselves ??? Just a test Number What is it , As a result, they themselves are Function!! Good! , Think about it, too , It can new, Create an instance or something

Object yes function, It turned out Function It's also Object, therefore Number and String It's also Object example , as follows :
typeof Object
// 'function'
Object instanceof Function
// true
Object instanceof Object
// true
Function instanceof Function
// true
Function instanceof Object
// true
String instanceof Object
// true
To sum up , Several data types are judged :
1.typeof You can judge simple data types , It doesn't work for complex data types ;
2.instanceof It is mainly used to judge complex data types ( Determine whether the current object is an instance of another object ) Returns a Boolean value ;
3.Object.prototype.toStringcall() Can accurately judge all data types ;
4.constructor Be able to judge multiple data types , and instanceof almost (null and undefined With the exception of )
I wrote this before , You can go and have a look : JS- Cycle to empty objects && Determine the type of data 5 A common way
版权声明
本文为[Yunhu doesn't like it?]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212330034981.html
边栏推荐
- 6、协议层次化和服务模型(重点)
- GAN网络笔记 MATLAB实现
- Wechat server configuration
- 7.5 线程等待终止
- Robot OS驱动开发
- SolidWorks hold down Ctrl and drag to copy entities
- 继华为仓颉后,再现4款国产编程语言,形式多样,有一款0代码
- warning: LF will be replaced by CRLF in composer. json.
- BUUCTF 刷题记录
- Ruixin microchip AI part development record section 1 "PC side environment construction 1"
猜你喜欢
随机推荐
New independent version of the tiktok machine full repair version with video tutorial
【接口测试基础】第五篇 | 接口用例设计详解
SolidWorks hold down Ctrl and drag to copy entities
多表创建视图问题:修改视图数据时报1062
C language: simple profit and bonus
Dynamic programming summary
warning: LF will be replaced by CRLF in composer. json.
6、協議層次化和服務模型(重點)
Use of database connection pool and Druid
vmware-vmx. Exe could not end the process
340-Leetcode 有效的字母异位词
The three secret softwares of the leaders are practical and powerful, which are powerful tools for office efficiency and workplace promotion
pytorch(五)——笔记
GO语言学习——Go语言基础之流程控制二
6. Hiérarchie des protocoles et modèle de service (clé)
数据库连接池和Druid的使用
7.3 创建线程
C language for complete square
入参有汉字,报错500,服务器内部错误
Textview tilt properties
![[wrapper (1)]](/img/78/362594cbf940d3ab89e6d9d8891a5e.png)








