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

[JavaScript]基本構文まとめ

Posted at

今回は、JavaScriptの基本構文についてまとめていきます。

変数の定義

let 変数名 = ;

定数の定義

const 定数名 = ;

if文

if文の閉じカッコに、セミコロンは不要

if (条件){
  処理
} else if (条件){
  処理
} else {
  処理
}

swich文

ある値によって処理を実行するという条件分岐ができる。

break;をつけないと、条件に当てはまっても次の処理が実行される。

switch (条件の値){
  case 値1:
    処理
    break;
  case 値2:
    処理
    break;
}

比較演算子

他の言語と少し違う

// aとbが等しい
a === b
// aとbが異なる
a !== b

while文

繰り返し処理ができる。
while文の閉じカッコに、セミコロンは不要

while (条件){
  処理
}

for文

繰り返し処理ができる。
for文の閉じカッコに、セミコロンは不要
while文に比べてシンプルに書くことができる。

for (変数の定義;条件式;変数の更新){
  処理
}

まとめ

生のJavascriptを触ることはほぼないので、よく使うものだけをまとめておきました!

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