const f = new Boolean(false); console.log(f == !f); // Outputs `true`

· · Web · 1 · 0 · 0

@neonpaul coecion! new Boolean creates an object wrapper, not a boolean value. so that’s describing {} == !{} which the dbl equals coerces to Number leading to 0 == !0 which is true.

@neonpaul the only real funkiness imho is that JS is designed to coerce an empty object to 0 instead of NaN.

@pixelpaperyarn well I think `==` coerces instances of Boolean to their equivalent boolean value, whereas `!` doesn't, it just sees a truthy object, so inverts it to `false`. Not that I'm complaining, i just find it interesting some of the weird pointless stuff you can do.

@neonpaul oh you’re right! and yes these weird little things are indeed interesting.

Sign in to participate in the conversation

Open social media for the UK