Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

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文 条件分岐

Posted at

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だった場合、実行される
この場合は、OKが出る

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

Comments

eufss0183
@eufss0183
JavaScript
let ok =false;

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

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

NOでは?

0

Let's comment your feelings that are more than good

Qiita Conference 2024 Autumn will be held!: 11/14(Thu) - 11/15(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

Takahiro Anno, Masaki Fujimoto, Yukihiro Matsumoto(Matz), Shusaku Uesugi / Nicolas Ishihara(Vercel Inc.)

View event details

Being held Article posting campaign

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?

Login to continue?

Login or Sign up with social account

Login or Sign up with your email address