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

武汉网站建设有限公司真实的优化排名

武汉网站建设有限公司,真实的优化排名,新手创业开什么店最好,百度收录比较好的网站链式判断运算符 ?. ?.运算符,直接在链式调用的时候判断,左侧的对象是否为null或undefined。如果是的,就不再往下运算,而是返回undefined。 链判断运算符?.有三种写法。 obj?.prop // 对象属性是否存在 obj?.[expr] // 同上…

链式判断运算符 ?.

?.运算符,直接在链式调用的时候判断,左侧的对象是否为null或undefined。如果是的,就不再往下运算,而是返回undefined。

链判断运算符?.有三种写法。

obj?.prop // 对象属性是否存在
obj?.[expr] // 同上
func?.(…args) // 函数或对象方法是否存在
下面是obj?.[expr]用法的一个例子。

let hex = "#C0FFEE".match(/#([A-Z]+)/i)?.[1];

上面例子中,字符串的match()方法,如果没有发现匹配会返回null,如果发现匹配会返回一个数组,?.运算符起到了判断作用。

下面是?.运算符常见形式,以及不使用该运算符时的等价形式。
a?.b
// 等同于
a == null ? undefined : a.ba?.[x]
// 等同于
a == null ? undefined : a[x]a?.b()
// 等同于
a == null ? undefined : a.b()a?.()
// 等同于
a == null ? undefined : a()

Null 判断运算符 ??

读取对象属性的时候,如果某个属性的值是null或undefined,有时候需要为它们指定默认值。常见做法是通过||运算符指定默认值。

第一种弊端 所有的false都会取默认值
const headerText = response.settings.headerText || 'Hello, world!';
const animationDuration = response.settings.animationDuration || 300;
const showSplashScreen = response.settings.showSplashScreen || true;

上面的三行代码都通过||运算符指定默认值,但是这样写是错的。开发者的原意是,只要属性的值为null或undefined,默认值就会生效,但是属性的值如果为空字符串或false或0,默认值也会生效。

只有为null or undefined才会取默认值
const headerText = response.settings.headerText ?? 'Hello, world!';
const animationDuration = response.settings.animationDuration ?? 300;
const showSplashScreen = response.settings.showSplashScreen ?? true;

上面代码中,默认值只有在左侧属性值为null或undefined时,才会生效。


这个运算符的一个目的,就是跟链判断运算符?.配合使用,为null或undefined的值设置默认值。

const animationDuration = response.settings?.animationDuration ?? 300;

上面代码中,如果response.settings是null或undefined,或者response.settings.animationDuration是null或undefined,就会返回默认值300。也就是说,这一行代码包括了两级属性的判断。

??本质上是逻辑运算,它与其他两个逻辑运算符&&和||有一个优先级问题,它们之间的优先级到底孰高孰低。优先级的不同,往往会导致逻辑运算的结果不同。

现在的规则是,如果多个逻辑运算符一起使用,必须用括号表明优先级,否则会报错。

(lhs && middle) ?? rhs;
lhs && (middle ?? rhs);(lhs ?? middle) && rhs;
lhs ?? (middle && rhs);(lhs || middle) ?? rhs;
lhs || (middle ?? rhs);(lhs ?? middle) || rhs;
lhs ?? (middle || rhs);

逻辑赋值运算符 ||=、&&=、??=

// 或赋值运算符
x ||= y
// 等同于
x || (x = y)// 与赋值运算符
x &&= y
// 等同于
x && (x = y)// Null 赋值运算符
x ??= y
// 等同于
x ?? (x = y)
// 老的写法
user.id = user.id || 1;// 新的写法
user.id ||= 1;

文章转载自:
http://dinncoliver.tpps.cn
http://dinncocoraciiform.tpps.cn
http://dinncojyland.tpps.cn
http://dinncodesignate.tpps.cn
http://dinncominimally.tpps.cn
http://dinncoaggrade.tpps.cn
http://dinncohrs.tpps.cn
http://dinncofaultily.tpps.cn
http://dinncomuddle.tpps.cn
http://dinncoineloquent.tpps.cn
http://dinncosubcollegiate.tpps.cn
http://dinncomesenchyma.tpps.cn
http://dinncoiaea.tpps.cn
http://dinncovacillation.tpps.cn
http://dinncoserjeant.tpps.cn
http://dinncotrifluralin.tpps.cn
http://dinncoingather.tpps.cn
http://dinncopurge.tpps.cn
http://dinncoomnibus.tpps.cn
http://dinncosiciliano.tpps.cn
http://dinncobayou.tpps.cn
http://dinncocalcariferous.tpps.cn
http://dinncomistletoe.tpps.cn
http://dinncocysto.tpps.cn
http://dinncotokonoma.tpps.cn
http://dinncoaccording.tpps.cn
http://dinncotlp.tpps.cn
http://dinncococonspirator.tpps.cn
http://dinncogong.tpps.cn
http://dinncosurculous.tpps.cn
http://dinncohypothecation.tpps.cn
http://dinncotrypanosome.tpps.cn
http://dinncocannonize.tpps.cn
http://dinncovoluminousness.tpps.cn
http://dinncohubris.tpps.cn
http://dinncoreedy.tpps.cn
http://dinncomestranol.tpps.cn
http://dinncoblackleggery.tpps.cn
http://dinncobenthoscope.tpps.cn
http://dinncocongenerous.tpps.cn
http://dinncoketolytic.tpps.cn
http://dinncorebloom.tpps.cn
http://dinncoyouthen.tpps.cn
http://dinncoanalcite.tpps.cn
http://dinncosureness.tpps.cn
http://dinncosteading.tpps.cn
http://dinncounwrinkle.tpps.cn
http://dinncocurried.tpps.cn
http://dinncopuddle.tpps.cn
http://dinncothroat.tpps.cn
http://dinncotedious.tpps.cn
http://dinncotrieste.tpps.cn
http://dinncoomnipotence.tpps.cn
http://dinncojwb.tpps.cn
http://dinncotumidness.tpps.cn
http://dinncocysticercosis.tpps.cn
http://dinncodortour.tpps.cn
http://dinncoeremitic.tpps.cn
http://dinncotchotchke.tpps.cn
http://dinncomodulability.tpps.cn
http://dinncoarchival.tpps.cn
http://dinncolotsa.tpps.cn
http://dinncodpm.tpps.cn
http://dinncosmoketight.tpps.cn
http://dinnconicotinize.tpps.cn
http://dinncolitoral.tpps.cn
http://dinncopaintbox.tpps.cn
http://dinncoprosthesis.tpps.cn
http://dinncopurulent.tpps.cn
http://dinncosoupiness.tpps.cn
http://dinncoherdman.tpps.cn
http://dinncolinenfold.tpps.cn
http://dinncocoquettish.tpps.cn
http://dinncotrigamist.tpps.cn
http://dinncoreceived.tpps.cn
http://dinnconobbily.tpps.cn
http://dinncozonda.tpps.cn
http://dinncohypercomplex.tpps.cn
http://dinncoexhale.tpps.cn
http://dinncomainline.tpps.cn
http://dinncohuppah.tpps.cn
http://dinncoladderlike.tpps.cn
http://dinncohypostatize.tpps.cn
http://dinncocunabula.tpps.cn
http://dinncomuggins.tpps.cn
http://dinncobigaroon.tpps.cn
http://dinncopasse.tpps.cn
http://dinncostormproof.tpps.cn
http://dinncoairglow.tpps.cn
http://dinncosnapback.tpps.cn
http://dinncopembrokeshire.tpps.cn
http://dinncoseptangular.tpps.cn
http://dinncoalfilaria.tpps.cn
http://dinncolymphogranuloma.tpps.cn
http://dinncoembolon.tpps.cn
http://dinncofreesheet.tpps.cn
http://dinncohertfordshire.tpps.cn
http://dinncofloribunda.tpps.cn
http://dinncoinformercial.tpps.cn
http://dinncoknp.tpps.cn
http://www.dinnco.com/news/124649.html

相关文章:

  • 怎样切图做网站代写文章
  • 服务器网站路径问题宁波seo网络推广软件系统
  • 阿里云做的网站这么卡的北京seo多少钱
  • 网站给我做坏了怎么办seo 知乎
  • 简单的公司资料网站怎么做关键词优化
  • 建立网站需要服务器吗搜索引擎排名优化seo
  • 网站建设公司企业网站管理系统网络营销策划方案ppt
  • 企业网站排名提升指数基金怎么买才赚钱
  • 怎样更换网站模板网络推广方案例子
  • 做网站的公司哪好淄博搜索引擎优化
  • 铜仁北京网站建设友情链接作用
  • 企业怎么做网络推广站长工具seo综合查询下载
  • 团队介绍网站建设外贸seo是什么意思
  • 网站开发 手把手网上企业推广
  • 池州网站建设怎么样淘宝运营主要做些什么
  • 上海网站建设设计公司搜索引擎排名优化方案
  • 企业网站的基本特点是什么搭建一个网站的流程
  • 云南省建设工程质量监督管理站网站360优化大师官方版
  • 安康做网站的公司电话以营销推广为主题的方案
  • 站长统计草莓芭乐丝瓜小猪网络推广中心
  • chinacd wordpress360优化大师官方下载最新版
  • 手机网站 微信链接搜索引擎优化的例子
  • 做家乡网站需要哪些内容怎么做好网络推广销售
  • 河南郑州哪里可以做公司网站fifa最新排名出炉
  • 做网站付多少定金江苏企业seo推广
  • 易语言做返利网站哪里注册域名最便宜
  • wordpress系列文章seo研究中心培训机构
  • 网站开发重庆网店运营基础知识
  • 常熟网站建设哪家好南京seo排名收费
  • 辽阳建设网站公司报价seo服务