JavaScript's Schrödinger's Boolean: Both True and False
Description
A two-part meme highlighting a notorious JavaScript language quirk. The top half is a screenshot of a browser's JavaScript console. The first command, 'new Boolean(false)', correctly returns a Boolean object with a value of {false}. The second command, 'new Boolean(new Boolean(false))', counter-intuitively returns a Boolean object with a value of {true}. The bottom half of the image uses the 'Skyrim 100' skill meme format, showing the word 'Javascript' with the number '100' next to it, implying mastery or a high level of absurdity. The humor is rooted in JavaScript's type coercion rules: while 'new Boolean(false)' creates an object with a false value, the object itself is 'truthy'. Therefore, passing this truthy object to another Boolean constructor results in a new Boolean object with a value of true. This is a classic 'wat' moment for developers and a textbook example of why using the Boolean object constructor is discouraged in favor of primitive boolean values
Comments
47Comment deleted
This is why the senior dev on your team insists that `if (!!someObject)` is the only way to be sure. They've been hurt before
JavaScript: where one extra heap allocation can promote even false to middle management - proof that with enough abstraction, reality is negotiable
This is the same JavaScript quirk that made us add "5+ years experience with TypeScript" to job postings - not for the type safety, but to filter out developers who still think new Boolean(false) is a good idea after their third production outage
In JavaScript, even false becomes true once you give it an object - same career path as most middle managers
Ah yes, the classic JavaScript interview question that separates those who've been burned from those about to be. When you use `new Boolean(false)`, JavaScript helpfully creates an object wrapper - because apparently primitive booleans weren't confusing enough. Since all objects are truthy (even ones wrapping false), your carefully crafted `if (!myBool)` check suddenly fails in spectacular fashion. It's like JavaScript looked at C++'s operator overloading footguns and said 'hold my beer.' This is why ESLint has a rule against using Boolean/Number/String constructors with `new`, and why senior devs instinctively reach for `Boolean(value)` or `!!value` instead. Remember: in JavaScript, `new Boolean(false) == true` is false, but `new Boolean(false) ? true : false` is true. Because consistency is overrated when you can have *flexibility*
JavaScript is the only stack where a heap allocation turns false into true - thanks to ToBoolean’s “objects are truthy” rule, which is why eslint ships no-new-wrappers
new Boolean(false) is truthy because in JS, mere existence outweighs actual value - the ultimate architectural pattern for legacy tolerance
JavaScript in one line: box false, get an object; box the object, ToBoolean says true - autoboxing, the only promotion where false gets a raise
nonnull pointer -> true (at least in c++) Comment deleted
bool(False) → False (in python) Comment deleted
seems logical Comment deleted
seems legit Comment deleted
Don't see any problem here :/ Comment deleted
JS fan 100 Comment deleted
IQ level - javascript Comment deleted
Hey hey Comment deleted
It creates new instance → returns true because creating was successful I guess? Comment deleted
+ Comment deleted
Who cares? JavaScript bad, SHIT, LoL funny meme 00))))0 Comment deleted
Yea that could be one of the only right things in JS, it's just telling you that indeed he did create it Comment deleted
new operator probably returns non-zero value Comment deleted
typeof new Boolean(true) is an object, and an object is true when casted to boolean Comment deleted
what about typeof new Boolean(false)? Comment deleted
Its still an object Comment deleted
Why typeof is not boolean? Comment deleted
because it's a Boolean(), not a boolean Comment deleted
Moreover, we are creating new instance of Boolean using new. It's no longer a primitive type, it is object Comment deleted
yes, that's what I meant Comment deleted
typeof new Boolean() === "object" because the Boolean object is an object wrapper for a boolean value https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean Comment deleted
Thanks Comment deleted
Could it ever be false though? Comment deleted
.value is undefined, if you want the typeof boolean value you have to use .valueOf Comment deleted
Another noobie frontender JS meme making fun of JS Comment deleted
let num = 123 num.toString() // "123" 123.toString() // err 123..toString() //"123" Comment deleted
I guess its because of commas? Like 5.5.toString() works too? Comment deleted
Interpreter thinks that after first dot comes floating part. When it comes to the second one it will recognize it as object's dot Comment deleted
Yeah that's what I was thinking. Comment deleted
LOL. Reminds of al of those nasty UDs in C.... Comment deleted
😂😂😂😂😂 Comment deleted
100% legit, not only in JS Comment deleted
Lol Js .. Comment deleted
Is it powered by JON? Comment deleted
Lol its because any object is true. Also the automatic casting converst values to something they make sense. At least they try. Comment deleted
Fuck this meme. I don't know to much about JS, but got experience in another languages and in most cases "new" will return you either true or false depending on if object was created or not. Comment deleted
you're talking nonsense in any high-level language Comment deleted
Just use Boolean instead of new Boolean. Everything just works perfectly. :) Comment deleted
actually it's a joke from statically typed language perspective but the moment you understand dynamically typed languages it stops to be funny as you can see new Boolean is an object wrapper for a boolean value. there are four state of a variable in Js: null, undefined, true(here is where dynamics apply if variable exists it is true) or false i will not go into details. so when you pass an argument to the first object wrapper it accepts the above states of the variable if the value of the argument is not of type boolean Comment deleted