Q:

javascript for

let str = "";

for (let i = 0; i < 9; i++) {
  str = str + i;
}

console.log(str);
// expected output: "012345678"
2
var texts = [
    'a1',
    'a2',
    'a3',
];

for (var i = 0; i < 3; i++) {
    console.log(texts[i]);
}
/* Result
a1
a2
a3
*/
2
//this loops through an array, 'cars', and logs each element to the console.
for (var i = 0; i < cars.length; i++) {
  //repeating code here:
  console.log(cars[i]);
}
6
var texts = [
    'a1',
    'a2',
    'a3',
];

for (var i = 0; i < texts.length; i++) {
    console.log(texts[i]);
}
/* Result
a1
a2
a3
*/
2
const array = ['hello', 'world', 'of', 'Corona'];

for (const item of array) {
  console.log(item);
}
7
for (let step = 0; step < 5; step++) {
  // Runs 5 times, with values of step 0 through 4.
  console.log(step);
}
0
1
2
3
4
0
const numbers = [1,2,3,4];

for(const item of numbers){
  console.log(item);
}
1
for (let i = 0; i < 9; i++) {
  str = str + i;
}
0

New to Communities?

Join the community