💻 Tech
In a JS/TS, you can resolve an undefined value into a default value with the coalescing operator ??
. This is useful if you want a short-circuit evaluation to return a default value when the value is null
or undefined
.
const value = undefined;
const result = value ?? "default";
console.log(result); // default