That's because comma is a language construct, which acts like a semicolon that waits for all operands to finish before returning the last value returned.
The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.
Since the last statement to finish returns false, the result of the whole operation is false.
const foo = typeoftrue, false;
console.log(foo);
// could be re-written asconst _ = typeoftrue; // not usedconst foo = false;
console.log(foo);
// another example: bar will contain false!const bar = 'a', 3, true, {}, Symbol(), false;
Marco Alka
Software Engineer, Technical Consultant & Mentor
That's because comma is a language construct, which acts like a semicolon that waits for all operands to finish before returning the last value returned.
Since the last statement to finish returns
false, the result of the whole operation is false.const foo = typeof true, false; console.log(foo); // could be re-written as const _ = typeof true; // not used const foo = false; console.log(foo); // another example: bar will contain false! const bar = 'a', 3, true, {}, Symbol(), false;Reference: MDN