Enumerable
Enumerable means that when we are in a loop, we are looping through all properties that have enumerable property set to true or false. We can have control over it, we can access them. The best way to see it, is by creating an object. There are a few ways to create an object but we will use the more complicated one, in which we can set an enumerable property.
// const heros = []; Object.defineProperty(heros, 'iron_man', { value: 'Iron Man', enumerable: true}); Object.defineProperty(heros, 'superman', { value: 'Superman', enumerable: true}); //
Now, if we will use for in loop we should see two keys in the output. iron_man and superman. But if we will try to add a third hero, with enumerable set to false, the output will stay the same. Because we blocked enumerable property and loop cannot access this.
// for(let p in heros) { console.log(p); //iron_man superman } Object.defineProperty(heros, 'batman', { value: 'Batman', enumerable: false}); for(let p in heros) { console.log(p); //iron_man superman } //
Iterator
In simple words it is another object, which is attached to for example an Array, String, Map or Set, that tells another function how to access other different values. They all have built-in iterators. The object has no built-in iterator.
// const heros = { 1: 'Iron Man', 2: 'Spider-Man' } for(let p of heros) { console.log(p); //Error, 'heros' is not iterable } //