【问题标题】:Javascript/Typescript: What does "??=" mean in code [duplicate]Javascript/Typescript:\"??=\" 在代码中是什么意思[重复]
【发布时间】:2023-01-26 18:20:19
【问题描述】:

我在一段 Typescript 代码中看到了以下内容:

const arrayAA: Record<
    someSchema['propX'],
    typeof arrayBB
    > = {};
    
for (const varB of arrayBB) {
    (arrayAA[someStringValue] ??= []).push(varB)
}

这里的“??=”是什么意思?

我在文档中找不到有关“??=”的任何信息。

【问题讨论】:

    标签: javascript typescript


    【解决方案1】:

    这是一个Nullish coalescing assignment (??=)。

    它只会在左操作数为空(空或未定义)时分配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-28
      • 2019-12-20
      • 2019-02-26
      • 1970-01-01
      • 2015-07-15
      • 2018-07-17
      • 1970-01-01
      • 2013-10-06
      相关资源
      最近更新 更多