$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · medium · #211

What is the output?

function f(x?: number) {
  return x ?? -1;
}
console.log(f(0), f());
  1. -1 -1
  2. 0 -1
  3. 0 undefined
  4. -1 0
?? only replaces null or undefined, so 0 is kept while the missing argument falls back.
Play Problem Solving ▸