Loops

1- For Loop (MDN)

Commonly used to iterate over an iterable like arrays, strings when keeping a track of index is needed. 

const myName = 'javascript';

for (let i = 0; i < myName.length; i++) {      //myName.length gives length of string/array
  console.log(myName[i]);
}

 

2- While Loop (MDN)

Commonly used when there is no need to keep track of index.

const myName = 'javascript';

let count = 0;

while (count < myName.length) {
  count++;
}

console.log(myName + ' has ' + count + ' characters.');         //this is known as string concatenation 

 

 

Discussion
Phan😉

Phan😉 4:14 PM, Tuesday 8th Dec, 2020

Thats all🤔

1

Naman Gupta

Naman Gupta 12:02 PM, Saturday 12th Dec, 2020

Hey. I have covered just the basics in this codelab. That was the aim. 😊