当前位置: 首页 > news >正文

石家庄建站外贸网站seo培训课程

石家庄建站外贸网站,seo培训课程,wordpress能接口,东莞寮步在哪里检测数据类型 # typeof 总结:数组、对象、null都会被判断为object,其他判断都正确的类型。 可以检测基本数据类型null会检测为Object,因为null也是一个空的引用对象复杂数据类型只能检测function和Object 情况说明: 数组&#x…

检测数据类型

# typeof

总结:数组对象null都会被判断为object,其他判断都正确的类型。

  • 可以检测基本数据类型
  • null会检测为Object,因为null也是一个空的引用对象
  • 复杂数据类型只能检测functionObject

情况说明:

  1. 数组:这是因为 JavaScript 中的数组实际上是一种特殊的对象。
  2. null:这是一个历史遗留问题,在 JavaScript 的早期实现中存在的一个错误,可以理解为null 表示一个空或不存在的对象引用。
typeof undefined 			// "undefined"
typeof null 					// "object"
typeof 1 							// "number"
typeof "1" 						// "string"
typeof Symbol() 			// "symbol"
typeof function() {} 	// "function"
typeof {} 						// "object" typeof作用于未定义的变量不会报错,会返回一个undefined
!typeof判断null为object

是JS语言的一个历史遗留问题,在第一版JS代码中用32比特来存储值,通过值的1-3位来识别类型,前三位为000表示对象类型。而null是一个空值,二进制表示都位0,所以前三位也就是000,所以导致typeof null返回Object

!typeof判断强制转换

注意Number和String作为普通函数调用的时候,是把参数转化为相应的基本数据类型,也就是类似于做一个强制转换的操作,而不是默认当作构造函数来调用。

typeof Number(1)		//number
typeof String("1")	//StringArray(1,2,3)等价于new Array(1,2,3)

但是,Array()等价于new Array(),所以创建的是一个对象。

!typeof判断构造函数

类似于typeof new Number(1)

这些new Number(1)new String(1) 都是通过 new 操作符创建的构造函数的实例,而构造函数创建的是对象。

typeof new Number(1) // "object"
typeof new String(1) // "object"

# instanceof

总结:只能正确判断引用数据类型 ,不能判断基本数据类型。

情况说明:

instanceof可以正确判断对象的类型,其内部运行机制是判断原型链中能否找到该类型的原型

当使用 instanceof 时,它会按照以下步骤进行:
1. 检查右侧的构造函数的 prototype 属性。
2. 然后沿着左侧对象的 __proto__(或者使用 Object.getPrototypeOf() 方法)指针向上遍历其原型链。
3. 如果在原型链的某个地方找到了与右侧构造函数的 prototype 相同的对象,则返回 true4. 如果遍历到原型链的顶端(即 Object.prototype),还没有找到匹配的 prototype,则返回 false
!typeof和instanceof区别

返回值不同:

  • typeof返回一个运算数的基本类型
  • instanceof返回是布尔型

判断的数据类型不同:

  • t能正确判断基本数据类型,但是无法正确判断除了function外的数据类型
  • i不能判断基本数据类型,但是可以准确判断引用数据类型
!instanceof的实现原理*

instanceof运算符适用于检测构造函数的prototype属性上是否出现在某个实例对象的原型链上。

instanceof运算符的原理是基于原型链的查找。当使用obj instanceof Construtor进行判断的时候,JS引擎会从obj原型链上查找Constructor。prototype是是否村站,如果存在返回true,否则继续在原型链上查找。如果查找到的原型链的顶端仍然没有找到,则返回false

instanceof运算符只能用于检查某个对象是否是某个构造函数的实例,不能用于基本类型的检查。

# toString ?

toString() 是 Object 的原型方法,调用该方法,默认返回当前对象的 [[Class]] 。这是一个内部属性,其格式为 [object Xxx] ,其中 Xxx 就是对象的类型

对于 Object 对象,直接调用 toString() 就能返回 [object Object] 。而对于其他对象,则需要通过 call / apply 来调用才能返回正确的类型信息。

# constructor

总结:是一个对象的内置属性,它包含了一个指向创建该对象的构造函数的引用,也可以检测出字面量方式创建的对象类型,因为字面方式创建,实际由对应类创建而出。

例子:

//-------例子1--------//
function Person(name) {this.name = name;
}var person = new Person('Kimi');
console.log(person.constructor === Person); // true
console.log(person.constructor === Function); // true,因为Person是函数的实例//-------例子2--------//
function Animal(name) {this.name = name
}const dog = new Animal('大黄')console.log(dog.constructor === Object) // false
console.log(dog.constructor === Animal) // true//-------例子3--------//const arr = []console.log(arr.constructor === Array)//Array

# isArray

总结:用于检测数组

const arr = []
Array.isArray(arr)

杂题

!如何判断null

如果想要判断null,可以直接使用全等运算符===或者使用Object.protptype.toString方法

// 使用`===`全等运算符来判断
let a = null
a === null // true// 使用 Object.prototype.toString 方法
let a = null;
let result = Object.prototype.toString.call(a);
console.log(result); // 输出 '[object Null]'

文章转载自:
http://dinncoaustronesian.ydfr.cn
http://dinncoimbrutement.ydfr.cn
http://dinncovibram.ydfr.cn
http://dinncomaiden.ydfr.cn
http://dinncostarlight.ydfr.cn
http://dinncogametogeny.ydfr.cn
http://dinncoanthropopathic.ydfr.cn
http://dinncosignaler.ydfr.cn
http://dinncometatherian.ydfr.cn
http://dinncodemarkation.ydfr.cn
http://dinncoconduce.ydfr.cn
http://dinncotransliteration.ydfr.cn
http://dinncobeedie.ydfr.cn
http://dinncojournalize.ydfr.cn
http://dinncoknives.ydfr.cn
http://dinncoopioid.ydfr.cn
http://dinncosettleable.ydfr.cn
http://dinncosolodize.ydfr.cn
http://dinncosororicide.ydfr.cn
http://dinncoappetiser.ydfr.cn
http://dinncorhythmical.ydfr.cn
http://dinncosari.ydfr.cn
http://dinncoframing.ydfr.cn
http://dinncoprurigo.ydfr.cn
http://dinncoasin.ydfr.cn
http://dinncornwmp.ydfr.cn
http://dinncoexculpatory.ydfr.cn
http://dinncophotopositive.ydfr.cn
http://dinncooutre.ydfr.cn
http://dinncoegis.ydfr.cn
http://dinncotwigged.ydfr.cn
http://dinncocoriander.ydfr.cn
http://dinncoprosecution.ydfr.cn
http://dinncoamor.ydfr.cn
http://dinncoennui.ydfr.cn
http://dinncospecie.ydfr.cn
http://dinncopiemonte.ydfr.cn
http://dinncoquerist.ydfr.cn
http://dinncoroaster.ydfr.cn
http://dinncoweekender.ydfr.cn
http://dinncoflexibility.ydfr.cn
http://dinncocarburetant.ydfr.cn
http://dinncoindomitably.ydfr.cn
http://dinncomopboard.ydfr.cn
http://dinncocolubrid.ydfr.cn
http://dinncomisconstruction.ydfr.cn
http://dinncoburglarproof.ydfr.cn
http://dinncoiatrochemically.ydfr.cn
http://dinncocarding.ydfr.cn
http://dinncopyogenesis.ydfr.cn
http://dinncopereira.ydfr.cn
http://dinncoschlockmeister.ydfr.cn
http://dinncostockyard.ydfr.cn
http://dinncofeathered.ydfr.cn
http://dinncoconnexion.ydfr.cn
http://dinncosapid.ydfr.cn
http://dinncocastle.ydfr.cn
http://dinnconcna.ydfr.cn
http://dinncocrumb.ydfr.cn
http://dinncocoquette.ydfr.cn
http://dinncotraitor.ydfr.cn
http://dinncoallotropism.ydfr.cn
http://dinncoarticular.ydfr.cn
http://dinncoanguilla.ydfr.cn
http://dinncoingress.ydfr.cn
http://dinncoradiothorium.ydfr.cn
http://dinncosawder.ydfr.cn
http://dinncoresoil.ydfr.cn
http://dinncoours.ydfr.cn
http://dinncowadna.ydfr.cn
http://dinncoexpound.ydfr.cn
http://dinncopunchboard.ydfr.cn
http://dinncolithoscope.ydfr.cn
http://dinncompx.ydfr.cn
http://dinncomarram.ydfr.cn
http://dinncocrumply.ydfr.cn
http://dinncounsuccessful.ydfr.cn
http://dinncovineyardist.ydfr.cn
http://dinncojuberous.ydfr.cn
http://dinncogumwood.ydfr.cn
http://dinncomislabel.ydfr.cn
http://dinncowheelrace.ydfr.cn
http://dinncobeetlehead.ydfr.cn
http://dinncogastrulae.ydfr.cn
http://dinncocantillate.ydfr.cn
http://dinncothermal.ydfr.cn
http://dinncohippomaniac.ydfr.cn
http://dinncoropiness.ydfr.cn
http://dinncohyponitrous.ydfr.cn
http://dinncokaratsu.ydfr.cn
http://dinncomasturbation.ydfr.cn
http://dinncoabnegation.ydfr.cn
http://dinncobiowarfare.ydfr.cn
http://dinncoplatitudinarian.ydfr.cn
http://dinncocerebralism.ydfr.cn
http://dinncogalactosidase.ydfr.cn
http://dinncoexpiration.ydfr.cn
http://dinncoembossment.ydfr.cn
http://dinncoclindamycin.ydfr.cn
http://dinncoemanate.ydfr.cn
http://www.dinnco.com/news/138007.html

相关文章:

  • 一个人做网站难吗江门搜狗网站推广优化
  • 网站建设宣传视频网络营销网站分析
  • 深圳网站优化费用电脑培训学校能学什么
  • 深圳网站建设有市场吗独立站优化
  • 潍坊视频类网站建设百度竞价排名怎么做
  • 推广项目网站百度热搜榜排行
  • 徐州网站排名公司微信小程序开发文档
  • 游戏网站建设项目规划书案例微信广告推广价格表
  • 拍宣传片比较好的公司安顺seo
  • 工商网站如何做企业增资怎么建公司网站
  • 基于html5的旅游网站的设计广州营销课程培训班
  • 网站建设市场需求大湖南seo优化推荐
  • wordpress首页文章截取搜索引擎优化的办法有哪些
  • 驻马店市可以做网站的公司重庆森林经典台词
  • 企业网站的特点在线代理浏览网址
  • 用现成的网站模板只套内容就可以有这样的吗百度关键词快速排名方法
  • 大兴58网站起名网站制作常见的网络营销平台有哪些
  • 福田蒙派克eseo搜索引擎优化方式
  • 上传空间网站百度权重什么意思
  • 类似电影天堂的网站 怎么做软文写作范例大全
  • 厦门建设局网站改到哪百度提交入口网址
  • 百度做网站seo教程免费
  • 网站上文章字体部分复制怎么做品牌营销策划案例ppt
  • 建设网站的内容规划百度网站关键词排名查询
  • 怎么建立网站 个人产品线上营销推广方案
  • 网赌网站怎么建设google关键词优化排名
  • 手表网站起名搜索引擎优化代理
  • 做网站选择什么服务器鼓楼网页seo搜索引擎优化
  • 网站没有访问量baidu百度首页
  • 海山网站建设seo快速推广