Home > Web Front-end > JS Tutorial > Day / Days of Code: Advanced Loops

Day / Days of Code: Advanced Loops

WBOY
Release: 2024-09-01 21:12:02
Original
623 people have browsed it

Day /  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}.`);
}
Copy after login

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!

The above is the detailed content of Day / Days of Code: Advanced Loops. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template