When we talk about iterators we mean we have more than one thing and we want to iterate through that collection and do something.
If you've used Array.push
, or Array.splice
, etc. they are mutable methods that update the object at the memory pointer.
Why does this matter? There are a couple of reasons, but an important one: In JS, it garbage collects on memory pointers. If you want to evaluate if it has changed or not, you need to evaluate based on properties if it was a mutable object pointing to the same space.
A useful tidbit that came out was the Object.freeze
method to prevent mutablility.
When it comes to managing state, control flow and code volume, there are few things more elegant than reducers.