Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active October 1, 2025 21:44
Show Gist options
  • Save rauschma/505256190982dec4f66dbf0a28872db4 to your computer and use it in GitHub Desktop.
Save rauschma/505256190982dec4f66dbf0a28872db4 to your computer and use it in GitHub Desktop.
// Triggered by: https://fediverse.zachleat.com/@zachleat/115300801628689509
// Interesting inconsistency...
// The reason is probably backward compatibility:
// Truthiness checks are often used to answer the question “Is this value an object?”
class MyBool {
#bool;
constructor(bool) {
this.#bool = bool;
}
[Symbol.toPrimitive]() {
return this.#bool;
}
}
const myBool = new MyBool(false);
console.log("%j %j %j %j",
Boolean(myBool), // true
!!(myBool), // true
'' + myBool, // "false"
Number(myBool), // 0
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment