Skip to content
DevMeme
3741 of 7435
JavaScript's Schrödinger's Boolean: Both True and False
Languages Post #4081, on Jan 6, 2022 in TG

JavaScript's Schrödinger's Boolean: Both True and False

Why is this Languages meme funny?

Level 1: False in a Box

Imagine you have a piece of paper that says “No” (like the word false). If you show just that paper, it clearly means “No.” But now put that paper inside a little box. If someone asks “Do you have something?”, you’d answer “Yes, I have a box” — the box itself counts as something (like a “true” thing) even though it’s holding a “No” inside. If you then put that box inside a bigger box, you’re still holding something, so you’d again answer “Yes!”. By wrapping a “No” inside one and then two layers of boxes, from the outside it weirdly looks like a “Yes.” This meme is playing with exactly that idea: in JavaScript, if you wrap a false value inside a box (an object), it acts true. Do it twice and it’s like you magically turned “No” into “Yes” just by adding boxes. It’s funny (and a bit absurd) because normally we don’t expect that you can change the meaning of false just by packaging it differently!

Level 2: True vs Truthy

In JavaScript, any value can be used in a condition (like an if statement), and values are classified as either truthy or falsy. Put simply, falsy values behave like false, and truthy values behave like true when evaluated in boolean contexts. The falsy list is short and memorable:

  • false (of course)
  • the number 0 (and -0, an edge-case)
  • "" (an empty string)
  • null and undefined
  • NaN (a special “not a number” value)

Everything else is truthy — which means it counts as true in an if or similar check. Importantly, any object is truthy in JavaScript, even an object that represents a negative or false concept.

Now, JavaScript has a quirk with its Boolean type. You can use Boolean as a function or as a constructor. If you call Boolean(x) as a regular function (without new), it will convert x into a simple true/false primitive. For example, Boolean(0) returns false, and Boolean("hello") returns true. But if you call new Boolean(x), you create a Boolean object instead of a primitive. That object contains a boolean value inside it, but because it’s an object, JavaScript treats it as truthy by default.

So if you do new Boolean(false), you get an object that holds the value false. However, if you use that object in a conditional, it will act as true, not false. You basically put the false inside a wrapper (an object), and the language only sees “hey, this is an object, that’s something!” and so it treats it as true. For example:

if (new Boolean(false)) {
  console.log("This executes, because the object is truthy!");
} else {
  console.log("This will never run.");
}

Even though the Boolean object was created with false inside, the if condition treats it as true, so the first branch runs. The meme takes this one step further: new Boolean( new Boolean(false) ). Here the inner part, new Boolean(false), as we saw, is a truthy object. So it’s like doing new Boolean(truthyValue), which will create a Boolean object set to true internally. The console screenshot is showing exactly that outcome: the first evaluation results in a Boolean {false}, and the second results in a Boolean {true} after nesting.

For someone new to JavaScript, this is pretty confusing! It highlights a sneaky difference between true and truthy. The meme essentially jokes, “look, I’ve leveled up my understanding of JavaScript’s weirdness!” It points out a type coercion surprise in a lighthearted way. In normal coding, you would just use the plain true or false values and avoid new Boolean entirely to prevent this kind of mix-up. But seeing it illustrated like this is a fun way to learn that even something as simple as booleans can have tricky behavior in JavaScript.

Level 3: True Lies

This meme highlights a notorious JavaScript type coercion oddity: using the Boolean constructor in a nested way to make false appear true. In the top panel (a browser console), the code:

new Boolean(false);               // Boolean {false}
new Boolean(new Boolean(false));  // Boolean {true}

produces a mind-bending result. The first line creates a Boolean object that contains the value false, and the console shows it as Boolean {false}. The second line wraps that object inside another Boolean constructor, yielding Boolean {true}. We’ve effectively flipped a false into true by double-wrapping it!

How is this possible? In JavaScript, the Boolean function can act in two ways. Call it like a regular function Boolean(x) and it will convert (coerce) x into a primitive true or false. But call it with the new keyword (new Boolean(x)) and it constructs a Boolean object instance. Here’s the quirk: all objects are truthy in JavaScript. It doesn’t matter if an object’s content is “false” – an object is a something, so it counts as true in boolean contexts. Thus, new Boolean(false) creates an object that holds false internally, yet if you check that object in an if statement or similar, it behaves as true. Nesting it one level further, new Boolean(new Boolean(false)) sees the inner object (which is truthy) and therefore produces an object with value true. This is a classic type-coercion trick, a truthiness edge-case that can flip logic on its head.

Seasoned developers can only shake their heads and laugh at this language quirk. It’s the kind of bizarre corner of the JavaScriptEcosystem you either learn from experience or hear about in programming folklore. We all quickly learn not to use new Boolean in real code (it’s almost always a bad idea unnecessary), because it leads to confusion exactly like this. But as a joke or trivia, it perfectly illustrates how language features can be unintuitive. It almost feels like turning two negatives into a positive in math or grammar: you take something false, wrap it up twice, and ta-da! it yields “true”. It’s not undefined behavior or a bug — the JavaScript spec explicitly defines it — but it sure can feel like a little magic trick (or a trap!) if you don't know what's happening.

The bottom panel with the bold “JavaScript 100” is a nod to the Elder Scrolls (Skyrim) game’s skill-leveling screen. It implies the person who pulled off this nested Boolean stunt has maxed out their JavaScript “truthiness” skill tree. Essentially, spotting and understanding this odd pattern is treated like an achievement unlock. Only a true JavaScript wizard (or someone who’s seen a lot of wacky code) would know that new Boolean(false) is always truthy. The meme humorously awards nerd cred for mastering such arcane knowledge. This is typical developer humor: taking a weird, rarely-used quirk of the language and framing it like you’ve discovered a secret cheat code in a game.

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

47
Anonymous ★ Top Pick 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
  1. Anonymous ★ Top Pick

    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

  2. Anonymous

    JavaScript: where one extra heap allocation can promote even false to middle management - proof that with enough abstraction, reality is negotiable

  3. Anonymous

    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

  4. Anonymous

    In JavaScript, even false becomes true once you give it an object - same career path as most middle managers

  5. Anonymous

    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*

  6. Anonymous

    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

  7. Anonymous

    new Boolean(false) is truthy because in JS, mere existence outweighs actual value - the ultimate architectural pattern for legacy tolerance

  8. Anonymous

    JavaScript in one line: box false, get an object; box the object, ToBoolean says true - autoboxing, the only promotion where false gets a raise

  9. dev_meme 4y

    nonnull pointer -> true (at least in c++)

    1. @RiedleroD 4y

      bool(False) → False (in python)

      1. dev_meme 4y

        seems logical

  10. @bezuhten 4y

    seems legit

  11. @ShiningFlames 4y

    Don't see any problem here :/

    1. @callofvoid0 4y

      JS fan 100

      1. @azizhakberdiev 4y

        IQ level - javascript

        1. Deleted Account 4y

          Hey hey

  12. @VladislavSmolyanoy 4y

    It creates new instance → returns true because creating was successful I guess?

    1. @saidov 4y

      +

    2. @mozilaip 4y

      Who cares? JavaScript bad, SHIT, LoL funny meme 00))))0

  13. @maggelia 4y

    Yea that could be one of the only right things in JS, it's just telling you that indeed he did create it

  14. @Valeron933 4y

    new operator probably returns non-zero value

  15. @SrZorro 4y

    typeof new Boolean(true) is an object, and an object is true when casted to boolean

    1. dev_meme 4y

      what about typeof new Boolean(false)?

      1. @SrZorro 4y

        Its still an object

    2. @LionElJonson 4y

      Why typeof is not boolean?

      1. @RiedleroD 4y

        because it's a Boolean(), not a boolean

        1. @azizhakberdiev 4y

          Moreover, we are creating new instance of Boolean using new. It's no longer a primitive type, it is object

          1. @RiedleroD 4y

            yes, that's what I meant

      2. @SrZorro 4y

        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

        1. @LionElJonson 4y

          Thanks

  16. @VladislavSmolyanoy 4y

    Could it ever be false though?

  17. @SrZorro 4y

    .value is undefined, if you want the typeof boolean value you have to use .valueOf

  18. @saidov 4y

    Another noobie frontender JS meme making fun of JS

  19. @azizhakberdiev 4y

    let num = 123 num.toString() // "123" 123.toString() // err 123..toString() //"123"

    1. @ZgGPuo8dZef58K6hxxGVj3Z2 4y

      I guess its because of commas? Like 5.5.toString() works too?

      1. @azizhakberdiev 4y

        Interpreter thinks that after first dot comes floating part. When it comes to the second one it will recognize it as object's dot

        1. @ZgGPuo8dZef58K6hxxGVj3Z2 4y

          Yeah that's what I was thinking.

  20. @Agent1378 4y

    LOL. Reminds of al of those nasty UDs in C....

  21. @ZgGPuo8dZef58K6hxxGVj3Z2 4y

    😂😂😂😂😂

  22. @cringy_frog 4y

    100% legit, not only in JS

  23. Deleted Account 4y

    Lol Js ..

  24. @ZgGPuo8dZef58K6hxxGVj3Z2 4y

    Is it powered by JON?

  25. dev_meme 4y

    Lol its because any object is true. Also the automatic casting converst values to something they make sense. At least they try.

  26. @almaredonfaust 4y

    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.

    1. dev_meme 4y

      you're talking nonsense in any high-level language

  27. @lol123a10 4y

    Just use Boolean instead of new Boolean. Everything just works perfectly. :)

  28. @ciser0 4y

    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

Use J and K for navigation