13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[javascript] クエスチョンマーク2つの演算子って何?

Last updated at Posted at 2020-06-18

こんなやつ

false ?? 'hoge'
=> false

検索しづらいけど調べると、Null合体演算子というやつらしい。

|| と違って、nullundefined 以外の値の時は左の値を返す。
左辺が ''0 の場合は左の値を評価して返す演算子。

いろんなパターン

null ?? 'hoge' // => 'hoge'
undefined ?? 'hoge' // => 'hoge'
false ?? 'hoge' // => false
0 ?? 'hoge' // => 0
'' ?? 'hoge' // => ''
NaN ?? 'hoge' // => NaN

参考:
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator

13
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?