Question discussion

What is the output of the following JavaScript code?console.log(0 || "a", 0 ?? "a", null ?? "b", "x" && "c");

1728Medium DSSSB TGT Computer Science 0 replies

What is the output of the following JavaScript code?

console.log(0 || "a", 0 ?? "a", null ?? "b", "x" && "c");
  • Aa 0 b c
  • Ba a b c
  • C0 0 b x
  • Da 0 null c
Correct answer: A

Explanation

|| skips the falsy 0 and gives "a"; ?? only skips null or undefined, so 0 stays 0 and null gives "b"; && returns the last operand "c" when the first is truthy.

Discussion 0

Nobody has replied yet. Start the discussion!