JavaScript For Loop

We need to run sometime some code/operation common for multiple elements in a list or array. Hence we need to loop.

Java script for loop have 3 part.

  1. initialization of variable
  2. test condition w.r.t to variable
  3. counter- could be increment or decrement
  • first it will do the initialization and test check the condition, if condition is  true , it will execute the block else exit the for loop.
  • it will execute the block until the condition is true.

Syntax:

Example code;

Output:

apple
banana
orange
guava

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top