LoginSignup
3
2

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

3
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
3
2