DEV Community

Jacob Stern
Jacob Stern

Posted on

3

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!

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay