Last active
October 1, 2025 21:44
-
-
Save rauschma/505256190982dec4f66dbf0a28872db4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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