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?

if文の条件分岐について

Posted at

最近、if文を見直してるんです。

if文の基本ってこうじゃないですか↓

if (条件式){
  処理
}else if (条件式){
  処理
}else{
  最終的な処理
}

ですよね。あってますか?

ifの詳細なコード(?)

if文をモジュールとか使わずに極力簡単に書くとこうなります。(知らんけど)

const a = 10;
const b ="10";

if (a===b){
   console.log("変数aとbは極力同じです");
}else if(a==b){
   console.log("変数aとbは同じです。');
}else {}

このコードは変数aとbが型が同じかどうかを検証するコードです。
論理演算子の"=="は型が違っても値が同じ場合trueを返し、"==="は値が同じでかつ型も同じならtrueを返すものです。
よって、変数aとbは値は同じだが、型が違うため、else ifの「変数aとbは同じです」がコンソールに出力されます。

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?