1
1

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

論理演算子(||,&&,!)の意味

1
Last updated at Posted at 2022-02-08

自己紹介

現在都内の企業でWebエンジニアのインターン生としてお世話になっている大学2年生です!
インターンや個人開発で学んだことや苦労したことを記事にしています!
よろしくお願いします🙇🏻‍♂️

はじめに

今回は論理演算子(||,&&,!)の意味についてアウトプットしていこうと思います!
論理演算子はtruly(trueと判定される値)か falsey(falseと判定される値)かの結果で値が決まります。

||の意味

||は左項がtrueなら左項を、左項がfalseなら右項を返す

const name = null;
const nameShow = name || "名前を入力してください";
console.log(nameShow);
//コンソール:名前を入力してください

&&(アンパーサンド)の意味

&&は左項がfalseyなら左項を、左項がtrulyなら右項を返す

const name2 = null;
const name2Show = name2 && "名前を入力してください";
console.log(name2Show);
//コンソール:null

!の意味

!は否定を意味する
左項がtrulyならfalseを、左項がfalseyならtrueを返す

const name3 = true;
console.log(!name3);
//コンソール:false
> !undefined
true
> !null
true
> !0
true
> !123
false
> !""
true
> !"hello"
false
> ![]
false
> !{}
false
1
1
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?