Day 6 Recap of 30DaysofJavaScript
August 10, 2022 • 2 min read
Finished Day 6! Let's recap!
So, what did I learn on Day 6 of 30DaysofJavaScript? Let's see!
Day 6 went over the various ways to use loops in JavaScript. We will go over each one briefly here.
Click here to follow along.
for Loops in JavaScript
For loops will continue to repeat it's block code until the condition specified is false.
for (initialization, condition, increment/decrement) {
// code goes here
}
The three conditions of the for loop are the initialization, condition, and increment/decrement. initialization creates a variable with an initial value. Conditions are typically a comparison to check if the variable has fufilled the condition. Then, you either increment or decrement the variable to get closer to the condition.
while Loops in JavaScript
WHile loops only have 1 condition, however, the variable changes in the loop rather than in the loop statement.
let i = 0
while (i <= 5) {
// code goes here
i++
}
for of Loops in JavaScript
For of loops are used to iterate through elekments in an array without needing the index of each element.
for (const element of arr) {
// code goes here
}
break & continue
The break keyword can be used to interupt a loop, while continue can skip over interations of the loop.
for (let i = 0; i <= 5 ; i++) {
if(i == 2){
continue
}
if (i == 4){
break
}
console.log(i) // this will print 0 1 3
}
And this is the end of my recap of Day 6 of 30DaysofJavaScript. Loops are decently easy to understand.
Day 7 should be coming out soon! Day 7 will mark the 1 week of me learning JavaScript! If you want to know when it comes out, subscribe to the blog below! Share if you found my content interesting, and consider buying me some boba with the link down below.
Until next time, wherever, and whenever you are, have an amazing day! Signing off.
If you liked this and would like to support, click the link below to send me a boba!!! 🧋