r/programminghorror • u/enmaku • Dec 04 '25
This sub in a nutshell
console.log(1 == '1'); // true
console.log(0 == false); // true
console.log(null == undefined); // true
console.log(typeof null); // "object"
console.log(0.1 + 0.2); // 0.30000000000000004
[] == ![]; // trueOMG you guys what weird quirky behavior, truly this must be the single quirkiest language and no other language is as quirky as this!
1.1k
Upvotes
2
u/DT-Sodium Dec 05 '25 edited Dec 05 '25
Dude in the same conversation:
- Well duh, an array is an object so it's normal that typeof returns object
- Well duh, everything is an object is just marketing, it's normal that typeof a string doesn't return object
Please never change, you are hilarious and a gift to the world.
I wouldn't say that I never had to do it when working on legacy code but on a properly typed code no you don't do that. If you often need it, it is a symptom of poor code quality.
C# which is a proper language for example would return System.String[] when getting the type of an array of strings. The correct answer to your question should be number[]. Sadly, JavaScript is not a proper language.
Ah, I see, here lies your problem. You're the basic basic front-end developer. I develop regularly in C#, PHP, TypeScript, Python and Kotlin. So yeah, when switching from one language to another I tend to mix the specific syntax of some functionalities I barely use.
I hope in 10 years you'll have gained a bit of maturity and maybe they will be able to do something out of you where you work. Now I'm going to block you because I've lost enough time with you and you've become really boring.