DEV Community

Discussion on: How to write IMMUTABLE code and never get stuck debugging again

dglsparsons profile image
Douglas Parsons Author

Hey, I'm glad you enjoyed the article <3.

That's a great question and thanks for asking. You're absolutely right about the iterator or counter variables changing. It's not something you can avoid really as it's so inherent to how loops work.

I don't have particular problem with that though (although in some languages you have to be careful, especially if writing asynchronous code that uses those variables). What's more important, in my opinion, is what you are doing in the iteration - are you mutating an array in place, or returning a new array? Using map and reduce where possible helps a lot.

Hope that helps!

carlyraejepsenstan profile image

I see - that question has bugged me a lot while I'm coding. Thanks for the advice!