Question #525
Submitted by Answiki
on 07/19/2021 at 03:15:35 PM UTC
What is the syntax of a for loop in JavaScript ?
Merged questions
Answer
Submitted by Answiki
on 07/19/2021 at 03:15:10 PM UTC
In JavaScript, the general syntax of a for loop is:
for ( [initialization] ; [condition] ; [increment]) {
// code block to be executed
}
Here is an example of a simple loop displaying numbers from 1 to 10:
for (var i=1 ; i<=10 ; i++) {
console.log (i);
}
Note that you can also use the following variants:
-
for ... in
loops through the properties of an object ; -
for ... of
loops through the values of an iterable object.
Question by Answiki 07/19/2021 at 03:15:35 PM
What is the syntax of a for loop in JavaScript ?
Answer by Answiki on 07/19/2021 at 03:15:10 PM
In JavaScript, the general syntax of a for loop is:
for ( [initialization] ; [condition] ; [increment]) {
// code block to be executed
}
Here is an example of a simple loop displaying numbers from 1 to 10:
for (var i=1 ; i<=10 ; i++) {
console.log (i);
}
Note that you can also use the following variants:
-
for ... in
loops through the properties of an object ; -
for ... of
loops through the values of an iterable object.
Question by Answiki 07/19/2021 at 03:09:26 PM
How to write a for loops in JavaScript?
# | ID | Query | URL | Count |
---|
Icons proudly provided by Friconix.