Open this example in the interactive library
Source code
function span(start, end = start + 5) {
return [start, end];
}
console.log(span(8), span(8, 10));
Sample output
[ 8, 13 ] [ 8, 10 ]

Bind a default parameter from an earlier argument in JavaScript.
Open this example in the interactive library
function span(start, end = start + 5) {
return [start, end];
}
console.log(span(8), span(8, 10));
[ 8, 13 ] [ 8, 10 ]