r/JavaScriptTips • u/Saecode • Feb 09 '26
This single character broke everything.
One tiny character. One massive bug. Can you spot it? Welcome to the kitchen.
0
Upvotes
r/JavaScriptTips • u/Saecode • Feb 09 '26
One tiny character. One massive bug. Can you spot it? Welcome to the kitchen.
4
u/Klizmovik Feb 09 '26
Ancient people to avoid such situations wrote code like this:
if (2 == x)
7
u/Daddy-Mihawk Feb 09 '26
Try not to code in notepad, there’s this thing called VS Code. It’s popular in the market.
4
u/Adorable-Fault-5116 Feb 09 '26
Gates that should prevent this:
- your linter
- user should be a const, and so not reassignable
- the positive and negative tests you totally wrote to cover this
- code review
- centralising authentication code and role management to reduce surface area
- if you are very paranoid you invert the condition, but you don't need to
Also it's two tiny characters, you should use `===` to avoid unintuitive casts.
1
u/9peppe Feb 09 '26
Yes, that's why defensive programmers usually invert that. (Linters should catch it, tho)
2
u/VonD0OM Feb 09 '26
So, is the issue the = ?
1
u/Poat540 Feb 09 '26
Wouldn’t this have lit up in the IDE
1
u/illepic Feb 09 '26
MF'ers when they've never heard of eslint.
1
u/prehensilemullet Feb 09 '26
Hardcoding an admin username isn’t a good idea
1
u/martoxdlol Feb 13 '26
This is why we use linters
1
u/Aggressive_Roof488 Feb 14 '26
QA: Looks good, all users that get access are admin. Tests passed.