why “true || undefined ? undefined : false;” returns “undefinied”?

I wrote this expression in chrome console:

true || undefined ? undefined : false;

and it returned:


How come? enter image description here


The condition (true || undefined) is true, hence, the ternary operator will take undefined as the result:

const condition = true || undefined;
console.log("condition:", condition);

console.log("result:", condition ? undefined : false);

If your goal is to split by the ||:

const result = true || (undefined ? undefined : false);

console.log("result:", result);