A read operation gets information from data without modifying it. Reads that obtain information from their arguments are calculations because they have no hidden inputs or outputs. section 6.2
Use these distinctions to classify common operations:
- Reads retrieve information without changing data; writes modify data. section 6.2
- Getting a shopping cart's item count or an item by name is a read; adding, removing, or updating items is a write. section 6.2
- A function can replace a write with a read by copying data, modifying the copy, and returning it. section 6.3
Separate a read from a write
Instead of using array.shift() for both behaviors, define first_element(array) to return array[0] without changing the array. Keep removal separate, then make drop_first(array) copy the array, shift the copy, and return it. Splitting the operation makes the read independently reusable. section 6.9
function first_element(array) {
return array[0]; #1
}
Inspect the minimal JavaScript implementation of a read that returns the first array element without modification. section 6.9


