An implicit output is information or an observable effect leaving a function through something other than its return value. Updating a global variable, modifying an array, or changing the DOM are examples. Return values make outputs explicit and easier to test, reuse, and control. section 4.7 section 4.8
Use these distinctions when examining a function:
- Arguments are explicit inputs; other information entering the function is an implicit input. section 4.7
- Return values are explicit outputs; other information or effects leaving the function are implicit outputs. section 4.7
- Replace an implicit output with a local result and return it, then perform the external update at the calling boundary. section 4.10 section 4.9
- Minimize implicit outputs even when an action cannot become a calculation; fewer hidden connections improve modularity, reuse, and testability. section 5.3 section 5.14
Making a cart update explicit
Instead of pushing directly into the global shopping_cart, copy the cart, add the item to the copy, return it, and assign that result outside the extracted function. The function then has explicit inputs and outputs rather than an implicit array mutation. section 4.10
function add_item_to_cart(name, price) { #1
shopping_cart =
add_item(shopping_cart, name, price);
calc_cart_total();
}
function add_item(cart, name, price) {
var new_cart = cart.slice(); #2
new_cart.push({ #3
name: name,
price: price
});
return new_cart; #4
}
This listing shows the complete conversion from global-array mutation to copy-on-write and a returned cart value. section 4.10
Asynchronous work cannot expose a later result through an immediate return value. Pass a callback instead, so the calculated value becomes an explicit output when the asynchronous operations finish. section 15.29

