LoginSignup
0
0

More than 1 year has passed since last update.

javascriptの||と&&について理解する

Last updated at Posted at 2021-07-27

||(パイプライン二つ)の意味

左側がfalseなら右側を返す

const num = null;
const fee = num || "金額未設定です";
console.log(fee); // 金額未設定です
javascriptのfalsyな値の一覧
  • false
  • 0
  • -0
  • ""
  • null
  • undefined
  • Nan

&&(アンパサンド二つ)の意味

左側がtrueなら右側を返す

const num2 = 100;
const fee2 = num2 && "何か設定されました";
console.log(fee2); //"何か設定されました"
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