0
0

More than 3 years have passed since last update.

JavaScript勉強の記録その3: for文

Last updated at Posted at 2020-01-04

JavaScriptでfor文

for (初期値; 条件式; 増減値) {ループ毎に行いたい処理;}
と書くことでループ処理ができる。

以下の例では1から10までをコンソールに表示します。

index.js
for (let i = 1; i <= 10; i++) {
  console.log(i)
}

// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// 10

ちなみに``(バッククオート)の中に、${式}と書くことで、文字列の中に式を展開することができます。 これをテンプレートリテラルと言うそうです。

index.js
for (let i = 1; i <= 10; i++) {
  console.log(`hello ${i}`)
}

// hello 1
// hello 2
// hello 3
// hello 4
// hello 5
// hello 6
// hello 7
// hello 8
// hello 9
// hello 10
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