1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[TypeScript] ?? と ||

Last updated at Posted at 2024-12-10

完全に自分用のメモ。
毎回「あれ?どっちがどっちだっけ?」ってなる:cry:

x = a ?? b

a が null または undefined の場合にのみ b を返す。

let a = '';
let b = 'default';

let x = a ?? b; // x は '' になる

x = a || b

a が「falsy」な値(false, 0, '', null, undefined, NaN)の場合に b を返す。

let a = '';
let b = 'default';

let x = a || b; // x は 'default' になる
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?