What is the output?
function f(x?: number) {
return x ?? -1;
}
console.log(f(0), f());
- -1 -1
- 0 -1
- 0 undefined
- -1 0
?? only replaces null or undefined, so 0 is kept while the missing argument falls back.function f(x?: number) {
return x ?? -1;
}
console.log(f(0), f());
?? only replaces null or undefined, so 0 is kept while the missing argument falls back.