Marta’s courier includes £50 cover unless an order says otherwise. Iris chose no cover for order 1042, so its insured_value is 0. You need a default that keeps that choice. You’ll then use the same technique for today’s country counts. The snake_case keys come from the shop platform’s schema. Keep those external names unchanged.
Keep the Chosen Insured Value
Python’s order.get("insured_value", 50) preserves 0 and supplies 50 for a missing key. JavaScript property access returns undefined when a key is absent from both the object and its prototype chain, the linked objects it inherits properties from. Plain objects have no built-in .get(), so order.get("insured_value", 50) throws TypeError: order.get is not a function.
An or-style fallback looks tempting when you’re replacing .get(). Predict what this JavaScript port puts on Iris’s label:
const order = { id: 1042, insured_value: 0 };
console.log(order.insured_value || 50);
Run it to check whether her choice survives:
50
The fallback replaces her 0 because ||, like Python’s or, selects the default for every falsy value. Their falsy values differ: empty arrays and objects are truthy in JavaScript, while empty lists and dictionaries are falsy in Python. Python’s order.get("insured_value") or 50 would also return 50. Replacing .get()’s default with an or-style fallback changed the question from “Is it missing?” to “Is it falsy?”
The nullish coalescing operator, ??, evaluates its right-hand expression only when the left is undefined or null. Python evaluates a .get() default argument even when the key exists. Use ?? for both orders: