DEV Community

loading...

For...of & For...in - How to Remember the Difference with ammo.

Brad Beggs
Curious and Persistent.
・1 min read

Ah, syntax. Your logic might be sound but miss those commas, brackets, or a typo turns > into '<', and bam! broken code. But, hopefully, your JSlinter catches and corrects those some of those errors.

While your linter will catch incorrect use of for...in, how does one remember the use case for for...of or for...in? Which is for iterating over objects or through arrays/strings?

Remember the difference of for...in & for...of.

  1. If you get shot and the bullet stays in your body, the doctor looks for the foreign object.

  2. If a {bullet: "Full Metal Jacket"} is in a javascript ammo{} object, a developer looks for...in object. The pun/trick is pronouncing for...in as “foreign.”

Do brush up on for..in usage as it doesn’t loop in an ordered fashion. This Bits of Code article explains well when to use for...in.

Other Memory Devices?

What tricks or methods do you use to remember syntax or bits of code?

References

ESLint Documentation on For..of
Bits of Code - for..in versus for..of Loops

Discussion (1)

Collapse
jazzi profile image
Ejazhussain7047

You can find many online platforms to purchase ammunition. You may have a lot of information about ammunition from different blogs. There are many types of night vision accessories, which you can purchase online. Thermal vision goggles are the latest form of thermal vision goggles. You can purchase it from the Going Dark online ammunition website.