Member-only story
For loop in javascript: Javascript Interview Questions #17 (ES6)
Learn what is for loops in javascript and how to use for loops in JavaScript with examples, Javascript interview questions #17
For Loop
In javascript, there are 3 different for
loops can be used to iterate over iterable variables.
In this article we will learn how to use for loops. For loop is used to iterate over the iterable elements.
Let’s see what is the syntax for loop in javascript.
for (expression; condition; updateExpression) {
// for loop body
}
Expression is used for declaring variables.
Condition is the part checks for the loop will continue or stop.
If the condition is false, the loop will finish execution.
If the condition is true, the loop continues to execute.
updateExpression is updating the expression value.
After each loop, the expression is updated until the condition became false.
For Loop usage
// program to display numbers from 0 to 5
const n = 5;
// looping from i = 0…