DEV Community

Jacob Stern
Jacob Stern

Posted on

Day 61 / 100 Days of Code: Advanced Loops

Fri, August 30, 2024

I’m currently in the second course of the Codecademy Full-Stack Engineer path. I recently completed the JavaScript Syntax I lesson and have finished the Arrays and Loops assignments in JavaScript Syntax II. Next up are Objects, Iterators, Errors and Debugging, Practice, and three Challenge Projects.

The main highlight today was learning about loops that were completely new to me, namely for..of and for..in loops. These work much like traditional for loops but are more concise, readable, and maintainable. Here’s a comparison:

// Traditional for loop
for (let i = 0; i < hobbies.length; i++) {
  console.log(`I enjoy ${hobbies[i]}.`);
}

// for..of loop
for (const hobby of hobbies) {
  console.log(`I enjoy ${hobby}.`);
}
Enter fullscreen mode Exit fullscreen mode

In for..of loops, iterators are completely abstracted, bringing the objects and elements themselves to the forefront. This shift in focus makes the code more readable. However, these are not complete replacements for traditional for loops, e.g.: they don’t support backward iteration, although break and continue statements are available.

Overall, I’m enjoying the journey and looking forward to the challenges ahead. The 100 Days of Code challenge has been not only a great way to stay motivated and track my progress, but the Dev community is awesome!

Top comments (0)