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?

【備忘録】Udemy講座まとめ JavaScript vol.4 if文 条件分岐

Last updated at Posted at 2024-10-25

if文

JavaScript
if (true){
console.log("OK");
}

コンソールにはOKが出る
()の中が条件となり、trueだった場合、{}の中が実行される
falseには実行されない

else文

JavaScript
let ok =false;

if (ok){
console.log("OK");
}else{
  console.log("NO");
}

elseはif文の()がfalseだった場合、実行される
この場合は、NOが出る

else if

JavaScript
let ok =false;
let maybeOk =true;

if (ok){
console.log("OK");
}
else if(maybeOk){
  console.log("maybe Ok");
}
else{
  console.log("NO");
}

この場合、maybe Okがコンソールに出る
まずif文が、「false」なので、else ifに行き、else ifが「true」の為、実行される

=== や !==

JavaScript
let okk = 1 === 1;
console.log(okk);

let okkk = 1 !== 2;
console.log(okkk);

両方、「true」が出る
「===」は、同じ値か、「!==」は違う値であれば、trueが表示される

0
0
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
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?