LoginSignup
0
0

More than 1 year has passed since last update.

Javascriptのbooleanの判定法超基礎

Posted at

0以外の数値型
"以外の文字列型
配列型
オブジェクト型

これらをifの条件式として扱う場合はtrue扱いになる。

//アラートが表示されるパターン
const userName = 'Hitsuji';
if(userName){
 alert(`こんにちは${userName}さん`)
}
//アラートが表示されるパターン
const address = '';
if(address){
 alert(`あなたは${userName}ですね?`):
}

!を付与すると真偽値が逆になる

//falseが変える
const flg = 
'JavaScript'.includes('a');
console.log(!flg);

!!を2回加えるとデータ型がbooleanになる

//結果: true
console.log(!!'Hitsuji'):
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