Nullish coalescing ??
`a ?? b` gives `a` unless it is `null` or `undefined`; only then it gives `b`.
The ?? operator looks at the left value. If it is null or undefined, it returns the right one. For any other value, it returns the left one, including 0, "" and false.
That is why it is used for defaults: you say "if it is missing, use this", without touching real values that happen to be falsy. With ||, a 0 or an empty string would also be replaced, which is often a bug.
The course uses it in console.log(process.env.DEMO_NAME ?? "friend");. An environment variable that does not exist is undefined, so you get "friend".
It is plain JavaScript: the type checker understands it (it removes null and undefined from the result type), and Node runs it as written.
Reach for it when: a value may be missing (`null` or `undefined`) and you want a default, but `0`, `""` and `false` are valid values.
Examples
Common mistake
const port: number | undefined = 0; console.log(port || 3000);
Why: `||` treats `0` as falsy and replaces it, even though it was a valid value.
How to write it: Use port ?? 3000 to replace only null or undefined.
