LoginSignup
0
0

More than 5 years have passed since last update.

會被 `||` 視為 falsey value 的值

Last updated at Posted at 2018-05-09

|| 是 JavaScript 裡面的 OR 邏輯運算子
會被它視為 falsy 的值有以下六個

  • undefined
  • null
  • NaN
  • false
  • 0
  • '' / ""

比較意外的是空字串也會被視為 falsy value

在 Chrome 的 console 直接執行看看的話會得到這樣的結果:

undefined || null || NaN || false || 0 || '' || "" || 'a string';

image

參考

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