0

Is there a way to make true = false. When I try that, it obviously returns an invalid left-hand assignment. This is something that I have been curious about for a while, and I would appreciate an answer. I have tried a lot of things, but I haven't figured out how to do it. Here's some things that I've tried so far:

true = false;
var true = false;
let true = false;
const true = false;
Boolean(true) = false;
true = !true;
var true = !true;
let true = !true;
const true = !true;
Boolean(true) = !true;
Amy
  • 1,114
  • 13
  • 35
myjobistobehappy
  • 736
  • 5
  • 16

1 Answers1

2

Because true and false are reserved keywords, there's no way to assign to them. Even if you did window.true = false, true would still be true.

This isn't necessarily the case with all primitives. in es4 you were allowed to reassign undefined to be whatever you want it to be. (see this related discussion - it talks about weather or not to bother safe-guarding against it, but it you could find it informative)

Scotty Jamison
  • 10,498
  • 2
  • 24
  • 30
  • 1
    `window.true` doesn't exist – myjobistobehappy Dec 11 '20 at 03:29
  • 1
    In node, window isn't a thing, you would do global.true instead. And yes, true isn't a property on either of those, but usually when you set a property on it, e.g. window.x = 2, then using x, e.g. x + 3, would work. I used it as an example, because in older versions of javascript you could do `window.undefined = 2`, but this is now how true/false behave. – Scotty Jamison Dec 11 '20 at 03:38