A default parameter supplies a fallback when a function call omits an argument or passes `undefined`. Write the initializer after the parameter name: `discount = 0`. The parameter can then be omitted without requiring a check for `undefined` inside the function. section 8.2.2
Calculate tax with an optional discount
In `src/index.ts`, `function calculateTax(amount: number, discount: number = 0) { return (amount * 1.2) - discount; }` accepts both `calculateTax(100, 0)` and `calculateTax(100)`. Both return `120`. Changing the fallback in the declaration changes it wherever the function uses `discount`. section 8.2.2
A default-initialized parameter is optional, but it has no `?` marker and must follow required parameters. It handles a missing argument, not arbitrary extra arguments; use a rest parameter when a function needs to collect additional values. section 8.2.2
A fallback does not fix unrelated type problems. In JavaScript, `sumPrices(first, second, third = 0)` returns `300` for two numeric arguments, avoiding the earlier `NaN` result. If an argument is the string `"100"`, addition still concatenates: the demonstrated result is `"1001000"`. section 3.3.3
Listing 8.8 Using a default parameter value in the index.ts file in the src folder
function calculateTax(amount, discount = 0) {
return (amount * 1.2) - discount;
}
let taxValue = calculateTax(100, 0);
console.log(`2 args: ${taxValue}`);
taxValue = calculateTax(100);
console.log(`1 arg: ${taxValue}`);
//taxValue = calculateTax(100, 10, 20);
//console.log(`3 args: ${taxValue}`);
See the complete `src/index.ts` tax example with the defaulted discount and calls using one or two arguments. section 8.2.2
The same pattern works in application functions: `applyDiscount(product, discount = 5)` gives callers a standard discount while allowing them to supply another value. section 4.5.5



















