An iterable is an object whose elements can be enumerated through JavaScript’s iteration protocol. It defines Symbol.iterator, which supplies an iterator controlling how values reach the caller. The iterator’s next method returns { value, done }, allowing consumers such as for...of to advance until iteration finishes. section 9.1 section 9.6
class Block {
index = 0;
constructor(index, previousHash, data = [], difficulty = 0) {
this.index = index;
this.previousHash = previousHash;
this.data = data;
this.nonce = 0;
this.difficulty = difficulty;
this.timestamp = Date.now();
this.hash = this.calculateHash();
}
//...
[Symbol.iterator]() {
return this.data[Symbol.iterator]();
}
}
A custom Block becomes iterable by delegating Symbol.iterator to its internal data array, so callers can consume its transactions directly. section 9.1.3
Iterable and iterator describe related but distinct roles. An iterator provides next; an iterable provides Symbol.iterator and returns an iterator. A random-number iterator therefore becomes usable with for...of only after it returns itself from Symbol.iterator. The same protocol powers the spread operator and supports custom collections such as trees, graphs, dictionaries, and directory traversals. section 9.1.3
Domain objects and generators
Making Blockchain, Block, and Transaction objects iterable enables generic validation with for...of and permits early exit when the first failure appears. Generator functions extend the pattern by producing iterable sequences lazily. A Blockchain generator can yield newly configured blocks indefinitely, while the caller limits consumption with break. Iterables also integrate with destructuring: a Validation object can yield its failure and success branches for concise state extraction. section 9.1.3 section 9.2.2 section 9.2
This protocol separates collection design from consumption. Consumers can use the same for...of, spread, or destructuring syntax regardless of the data type. JavaScript also supports asynchronous counterparts: async iterators return promises from next, and async generators are consumed with for await...of. section 9.1.3 section 9.6






