当前位置:网站首页>JS four formulas for judging data types
JS four formulas for judging data types
2022-07-29 00:02:00 【Fairy loves fish】
1.Js Determine the type of data 4 Kind of ⽅ type
Js data type es5 6 Type of data :string、number、boolean、object(Data、function、Array)、null、undefined
Es6 Added in ⼀ Type of data :symbol: Express independence ⼀⽆⼆ Value , most ⼤ Of ⽤ Law is ⽤ To define the object ⼀ Property name ,⽆ On inequality at all times
var s1 = Symbol("symbol");
1.typeof
- For basic types , except null outside , Can return the correct result .
- For citation ⽤ type , except function outside ,⼀ Law return object type .
- about null , return object type .
- about function return function type .
Typeof NaN = number
Typeof null = object
Typeof object = function Object/Array/String/Number/Boolean/Date/RegExp All constructors
Typeof {} = object
typeof console.log = ‘function’ The function itself
typeof console.log() = ‘undefined’ shipment ⾏ function , Default return undefined
2.instanceof
test A Whether it is B Example ,⽐ a A._proto Whether and B.prototype equal
,instanceof Can only ⽤ To determine whether the two objects belong to the instance relationship , ⽽ Can't judge ⼀ Which type of object instances belong to .
[] instanceof Array
{} instanceof Object
instanceof (A,B) = {
var L = A.__proto__;
var R = B.prototype;
if(L === R) {
// A The internal properties of __proto__ Point to B Prototype object
return true;
}
return false;
}
3.constructor
- null and undefined yes ⽆ Effective object , So there won't be constructor There is , These two types of data need to be passed through other ⽅ To judge .
‘’.constructor === ‘String’
New Number(1).constructor === ‘Number’
New Function().constructor === ‘function’
4.toString
Object The prototype of the ⽅ Law , Returns the... Of the current object [[Class]]
Object.prototype.toString.call(‘’) // [[Object String]]
Object.prototype.toString.call(new Error()) ; // [object Error]
Object.prototype.toString.call(document) ; // [object HTMLDocument]
Object.prototype.toString.call(window) ; //[object global] window Global object global Introduction of ⽤
边栏推荐
- PIP image download
- 1-6 state与绑定事件
- pycharm配置运行环境
- mysql索引失效的常见9种原因详解
- Worthington -- Specification of Worthington trypsin inhibitor
- VMware VCSA 7.0 Install
- With the help of rpa+lcap, the enterprise treasurer management can be upgraded digitally
- Worthington - chemical properties and related studies of Worthington trypsin
- laptop外接显示器
- Leetcode64. 最小路径和
猜你喜欢

Powercli VMware vCenter deploys conventional new VMS in batch through self built PXE server with one click

多传感器融合定位(三)——惯性技术

Create AP hotspots for imx6 development board QT system based on rtl8723 cross compile iptables

SAP 临时表空间错误处理

Jincang database kingbasees client programming interface guide ODBC (2. Overview)

Powercl batch creates and manages virtual switches

【TA-霜狼_may-《百人计划》】美术2.2 模型基础

GhostNets on Heterogeneous Devices via Cheap Operations

【C】 Introduction and Simulation Implementation of ATOI and offsetof

What is a driver signature and how does the driver get a digital signature?
随机推荐
Websocket heartbeat mechanism (keep alive mechanism)
EN 1935 building hardware. Single axis hinge - CE certification
Apple's official website is being updated to maintain the apple store. Products such as the iPhone 13 / pro of the Bank of China will enjoy a maximum discount of 600 yuan
Leetcode64. 最小路径和
The failure rate is as high as 80%. How to correctly complete the strategic planning of digital transformation?
双重for循环优化
【C】atoi和offsetof的介绍和模拟实现
【C】 Introduction and Simulation Implementation of ATOI and offsetof
Worthington -- Specification of Worthington trypsin inhibitor
VMware VCSA 7.0 Install
fastdfs工作原理(技术原理)
Use pytoch to quickly train the network model
Machine learning problem notes
SAP temporary tablespace error handling
sql 左连接,内连接 的写法「建议收藏」
C language n*n matrix evaluation and inverse matrix [easy to understand]
Servlet运行原理_API详解_请求响应构造进阶之路(Servlet_2)
【C】逆序字符串(俩种递归思路)
Worthington - chemical properties and related studies of Worthington trypsin
Jincang database kingbasees client programming interface guide ODBC (2. Overview)