0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【React初心者メモ】三項演算子(? : )

Last updated at Posted at 2025-06-07

三項演算子とは

以下のように条件によって値を選ぶ短縮表現です。

条件式 ? 真の場合の値 : 偽の場合の値

具体例

三項演算子の場合は以下のようになります。

const age = 20;
const message = age >= 18 ? "成人です" : "未成年です";
console.log(message);  // "成人です"

if文の場合は以下のようになります。

const age = 20;
if (age >= 18) {
  message = "成人です";
} else {
  message = "未成年です";
}
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?