JavaScript Crash Course for Beginners-3

Welcome to part-3 of the series. You can find part-2 here.

We will start with loops in this part.

The first loop which will look is the traditional for loop, which is their in all languages.

Let’s look into the for loop below -

for(let i=0; i <= 10; i++){
console.log(`Loop Number - ${i}`);
}

Now, the flow of the loop is like for the first time let i=0 will run. After that i <= 10 will run. Now it will be true because 0 is less than or equal to 10. And, so the output of Loop Number- 0 will be printed.

Next, time the i++ will run, which is equivalent to i = i + 1. So, the i is now 1. Again the condition i <= 10 will run. Now it will be true because 1 is less than or equal to 10. And, so the output of Loop Number- 1 will be printed.

The loop will run till i is 10 and will print the outputs. Now, when i will be 11 after the increment and the condition i <= 10 will run. It will be false because 10 is less then equal to 10 will be false. So, the loop will end and come out.

Image for post
Image for post
For loop

You can read rest of the article from my blog post. The link for the same is below.

This completes part-3 of the series. You can find the last part here.

You can find the jsbins used in this part below.
https://jsbin.com/giluqiy/edit?js,console
https://jsbin.com/qucimim/edit?js,console

Written by

UI Lead- ReactJS, JavaScript and everything in-between.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store