13
11

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 5 years have passed since last update.

【js】論理演算子を使って変数を代入する

Posted at

論理演算子を使って変数代入する時のまとめ

【例】
var c = a && b;
var d = a || b;

【意味】&& のaが真ならばbを代入。|| のaが真ならばaを代入。

【注意】これを使う時はaやbの型に注意。例えばNumber型で偽とは0の時といったように。

こうすることで変数を二つ書くことを省略できてソースが簡略化できる。

13
11
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
13
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?