4
2

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でif文の条件式に変数だけを記述するやつ

Posted at

よく忘れるのでメモ

JavaScriptでは 0, "", undefined, null は false になる

以下のようなよくあるif文。存在チェックなどに使われています。
この場合、例えばhogeがundefinedだとif文の中に入ります。

if(!hoge) {
  ・・・
}

JavaScriptでは以下の値はfalseとみなされます。

  • 空文字("")
  • 数値の0
  • NaN
  • null
  • undefined
4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?