当前位置:网站首页>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 ⽤
边栏推荐
- GhostNets on Heterogeneous Devices via Cheap Operations
- 【C】 Introduction and Simulation Implementation of ATOI and offsetof
- What do you need to bring with you for the NPDP exam? Stationery carrying instructions
- After SAP Oracle replicates a new instance, the remote connection of the database reports an error ora-01031
- 基因组 DNA 分离丨Worthington核糖核酸酶A
- 连接池-归还连接详解(下)
- 1-6 state and binding events
- 考过HCIP入职心仪公司,分享华为认证学习经历及心得
- Arm-A53资料「建议收藏」
- 1-8 basic use of props
猜你喜欢

DevOps在物联网解决方案中的应用

Machine learning problem notes

After SAP Oracle replicates a new instance, the remote connection of the database reports an error ora-01031

【C】atoi和offsetof的介绍和模拟实现

Genomic DNA isolation Worthington ribonuclease A

YOLOV5学习笔记(一)——原理概述

With the help of rpa+lcap, the enterprise treasurer management can be upgraded digitally

【C】替换空格,宏实现整数的二进制奇偶位交换

Leetcode60. permutation sequence

多传感器融合定位(三)——惯性技术
随机推荐
EN 1873 assembly accessories for roofing - plastic single roof lamps - CE certification
leetcode 763. Partition Labels 划分字母区间(中等)
双重for循环优化
Powercli batch add esxi to vCenter
@Transactional 注解使用详解
基因组 DNA 分离丨Worthington核糖核酸酶A
NAT如何配置地址转换
【MySQL 8】Generated Invisible Primary Keys(GIPK)
Worthington -- Specification of Worthington trypsin inhibitor
VMware VCSA 7.0 Install
Leetcode63. Different paths II
数据中台的那些“经验与陷阱”
【TA-霜狼_may-《百人计划》】美术2.2 模型基础
[TA frost wolf _may- "hundred people plan"] art 2.2 model basis
器利而工善,以RPA+LCAP赋能企业司库管理数字化升级
JS advanced ES6 ~ es13 new features
Tyrosine decarboxylase -- characteristics of tyrosine decarboxylase of Streptococcus faecalis in Worthington
Worthington - chemical properties and related studies of Worthington trypsin
多传感器融合定位(二)——基于地图的定位
1-5 类式组件