Javascript for Loop

How to use the javascript for loop

How to use the javascript for loop.png

Below shows a typical use of the For Loop.

Additionally a template literal is used along with a couple of conditional ternary operators.

Note that back-ticks (`) are used to denote a template literal.

for (let index = 10; index >= 0; index--) {
  console.log(
    `${index === 10 ? "Ignition sequence" : ""}  ${index} ${
      index === 0 ? "LIFT OFF!!!" : ""
    }`
  );
}

Ouput will be:

Ignition sequence  10
  9
  8
  7
  6
  5
  4
  3
  2
  1
  0 LIFT OFF!!!

Author