Some numbers must never be negative: items in stock, seats left, a volume level, a counter of unread messages. A bug elsewhere writes stock -= 5 when only 3 are left, and now the shop shows -2 items. Instead of checking at every place that writes, the object itself can guard the value: a property with a getter and a setter decides what is stored.
Write defineNonNegative(object, key, initial) in non-negative.js. It adds a property key to object whose value can never go below zero.
Reading the property gives the current value, starting from initial (0 when missing).
Writing a number from 0 up stores it. Fractions and Infinity are fine.
Writing a negative number stores 0, so object.stock -= 5 stops at 0. Writing -0 stores 0.
Writing anything that is not a number (a string, null, undefined, a boolean, an object, a BigInt) or NaN throws a TypeError, and the value stays what it was.
initial follows the same rules: a negative one becomes 0, and one that is not a number, or NaN, throws a TypeError.
The property is enumerable: it shows up in Object.keys and in JSON.stringify.
No other property is added to the object: the value is not stored in a second, visible property.
Each property has its own value: two keys on one object, or the same key on two objects, never share one. The object's other properties are not changed.