The Lit Element repository contains a function called range that utilizes the ??=
operator. This operator resembles the nullish coalescing operator but with an equal sign. Do you know what this specific operator is called?
Below is the complete code snippet for your reference.
/**
* Returns an iterable of integers from `start` to `end` (exclusive)
* incrementing by `step`.
*
* If `start` is omitted, the range starts at `0`. `step` defaults to `1`.
*
* @example
*
* ts
* render() {
* return html`
* ${map(range(8), () => html`<div class="cell"></div>`)}
* `;
* }
*
*/
export function range(end: number): Iterable<number>;
export function range(
start: number,
end: number,
step?: number,
): Iterable<number>;
export function* range(startOrEnd: number, end?: number, step = 1) {
const start = end === undefined ? 0 : startOrEnd;
end ??= startOrEnd;
for (let i = start; step > 0 ? i < end : end < i; i += step) {
yield i;
}
}