Suppose a chart is usually 800 pixels wide, but callers sometimes need a smaller one. A default parameter puts the usual value in the function signature: `function approvalsChart(ratings, width = 800, height = width / 2) { /* ... */ }`. A default applies when its argument is omitted or is `undefined`; a supplied value takes its place. section 15.1
Follow the chart sizes
Call `approvalsChart(nationalRatings)` and `width` becomes 800; `height` is then calculated as 400. Call `approvalsChart(georgiaRatings, 400)` and the supplied width makes the default height 200. The height expression can use `width` because it appears earlier in the parameter list. section 15.1
Three rules make defaults easier to use:
- A default expression is evaluated when needed, not fixed when the function is written. In an object method, it can read `this`: changing `ajax.host` changes the URL produced by a later `ajax.load()` call without an argument. section 15.1
- Defaults belong to parameter positions. With `function range(min = 0, max)`, `range(10)` sets `min` to 10; it does not move 10 into `max`. Put required parameters before optional ones instead of expecting arguments to shift. section 15.1
- Defaults handle expected parameters. A rest parameter serves a different job: gathering a variable number of remaining arguments into an array. section 15.2 section 15.5
Listing 15.5. Calling getRatings only once
When each chart method is called alone, its ratings parameter defaults to `this.getRatings()`. When both charts are needed, their caller calculates ratings once and passes that result to each method, avoiding the second calculation. section 15.2
Defaults can also fill missing object settings, but that is a different operation: `Object.assign({ width: 900, height: 500 }, options)` builds map options by copying properties, with later objects overriding earlier ones. For practice, give a `car` function a default seat count, then use a rest parameter in its `board` method to handle passengers who fit and those who do not. section 10.1 section 15.5



















