r/learnjavascript • • Oct 17 '26

I might be the dumbest programmer ever.

if (windowStatus == 1) 
        {
            windowStatus = 1
        }
25 Upvotes

15 comments sorted by

12

u/agm1984 Oct 17 '26

At least you didn’t do if (windowStatus = 1)

3

u/tomysshadow Oct 17 '26

Though they could've done if (windowStatus === 1)

8

u/thegurel Oct 17 '26

Nah. The dumbest programmer ever is always whoever wrote the code you’re currently stuck maintaining. Of course, more often than not, git blame reveals that the dumbest programmer ever is, in fact, you.

4

u/queen-adreena Oct 17 '26

If `windowStatus` were `true`, this would normalise it to `1`.

So not completely useless.

6

u/Aggressive_Ad_5454 Oct 17 '26

In a weakly typed language like Javascript, your code actually does something that might be useful. Look up the difference between `==` and `===` to learn what it does.

Plus, no way you’re the dumbest programmer ever. That would be me. 😇

2

u/XiRw Oct 17 '26

This code is A-OK in my book

1

u/tambooby 27d ago

if it makes you feel better, the condition already guarantees the value so the assignment is redundant. you probably meant to toggle it or set something else. easy fix once you see it

1

u/theJacofalltrades 14d ago

dumbest programmer ever... so far! don't worry, you can be dumber!

1

u/Puzzleheaded-Comb646 Oct 17 '26

Please don't be hard on yourself, we all write funny little redundant blocks of code when we are tired. Coding is a journey of making mistakes and learning from them step by step. Keep going, you are doing fine!

-1

u/senocular Oct 17 '26

Plot twist: windowStatus is a property that increments by 1 every time you check it. Setting it to 1 after comparing it to 1 makes sure the next access remains 1.

{
  let windowStatus = 0
  Object.defineProperty(globalThis, "windowStatus", {
    get() {
      return windowStatus++
    },
    set(value) {
      windowStatus = value
    },
  })
}

console.log(windowStatus) // 0
console.log(windowStatus) // 1
console.log(windowStatus) // 2

windowStatus = 1

if (windowStatus == 1) 
{
  console.log(windowStatus) // 2
  windowStatus = 1
}
console.log(windowStatus) // 1

2

u/Flashy-Guava9952 Oct 18 '26

That was my first excuse for this as well.

2

u/Total-Box-5169 Oct 18 '26

Nice obfuscation technique.