LoginSignup
0
0

More than 1 year has passed since last update.

【今日の学びメモ】JavaScript で Falsy な値を使った判定をする

Posted at

JavaScript で

A && B

と書いた場合、 A の値が Falsy だと A の値そのものが返ってくる。

例えば以下のような感じ。

console.log(undefined && true);
>> undefined

返り値をbooleanに固定したければ、否定演算子!を二つ重ねて

console.log(!!undefined && true);
>> false

とすれば良い。

undefinedではなく!!undefinedとする意味がわからなかったのでメモ。

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