LoginSignup
0
0

More than 3 years have passed since last update.

=== undefined よりも == null を使おう

Posted at

以下のコードを見てくれ

const data = await fetchData( ... );
if (data.flag === undefined) {
  ...
}

=== undefined を使っているがそれは意図して使っているのか?

== null=== undefinedには以下のような違いがある

== null

null もしくは undefined と一致

=== undefined

undefinedと一致

つまりnullはOK!undefinedはダメ!という状況でしか使わないのだ!
いつ紛れ込むかわからないnullのことを考えると == nullを使うのが吉だ!

0
0
1

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
0
0