Two Important JavaScript Loops And A Book Recommendation

Though I was understanding the beginning concepts of JavaScript well and able to follow along with the lessons, there was undoubtedly something missing. Well, I think I have found it.

A Helpful Book

I am not sure where the recommendation came from, probably a Medium article, but there happen to be a series of books called “You Don’t Know JS,” by Kyle Simpson. The first book of the series is called, “Up and Going,” and is intended for JS beginners (like me). Best of all it is FREE for the Kindle as well as Free on Github.

This book is highly recommended and very helpful if you started your study of JavaScript on a platform such as CodeSchool or Free Code Camp. These sites are great and will get you on your feet, but they tend to leave gaps in the fundamentals that are key to growing faster in your understanding of JS.

Combining Similar Concepts

This book may seem basic for some, but basic was just what I needed. Also, many concepts intersect to help you broaden your understanding faster ……. such as this:

Let’s look at a While loop (given as an example in above book):

1

2

3

4

5

6

7

8

9

while(numOfCustomers>0){

console.log("How may I help you?");

// help the customer...

numOfCustomers=numOfCustomers-1;

The above javascript loop sets the condition from the outset: If the number of customers is greater than 0, then do something.

Well what if you wanted to do something one time, first, and then consider the condition?

Basically it would be the same thing, but reversed. This is called a (do..While) loop:

1

2

3

4

5

6

7

8

9

10

11

do{

console.log("How may I help you?");

// help the customer...

numOfCustomers=numOfCustomers-1;

}while(numOfCustomers>0);

The above JavaScript loop does something first, and then sets the condition afterwards. The former does something if a condition is met and will continue to do something if the condition is met, while the latter does something one time first before considering the condition.

I had not heard of a do..While loop yet until they tied the two together in this book. If one understands a While loop already, then something like a do..While loop is retained instantly.

Anyways, the book is free! If you are a JavaScript newbie get it!

Have any other JavaScript books been helpful to you. Please share them below in the comments!!