I was wondering why new Boolean(new Boolean(false)) returns true, and not false.
Asked
Active
Viewed 39 times
0
jonrsharpe
- 107,083
- 22
- 201
- 376
MrFrenzoid
- 569
- 3
- 15
-
4`new Boolean` is a boxed primitive, as such an object, and truthy. Note that the result is also boxed, and not a primitive (`a !== true`). – ASDFGerte Jan 07 '22 at 17:17
-
every object, except `null` is truthy. – Nina Scholz Jan 07 '22 at 17:17
-
4And `null` isn't an object, despite the `typeof null === "object"` bug. (Yes, bug. Confirmed by Eich, a bug in his original implementation that was quickly replicated, and then of course became necessary for backward compatibility and, eventually, specified behavior.) – T.J. Crowder Jan 07 '22 at 17:19
-
1`new Boolean(new Boolean(false))` [performs](//tc39.es/ecma262/#sec-boolean-constructor-boolean-value) [OrdinaryCreateFromConstructor](//tc39.es/ecma262/#sec-ordinarycreatefromconstructor) which “creates an [ordinary object](//tc39.es/ecma262/#ordinary-object)” with the [[BooleanData]] internal slot set to [ToBoolean](//tc39.es/ecma262/#sec-toboolean) of its argument, which is `true` for Objects. `new Boolean(`…`)` is an object. – Sebastian Simon Jan 07 '22 at 17:21
-
Wow, i didn't know that one. Always thought, that the authors considered the `typeof null` thing as normal - gives me back some hope :) – ASDFGerte Jan 07 '22 at 17:26
-
Wow, thank you so much guys, i've learned a lot from these, i didn't expect so much aid :) – MrFrenzoid Jan 07 '22 at 17:28