3 ms·
Does anybody really know why JS's type system was designed the way it was? It seems so out of whack with what people want out of a language, dynamically typed o
by unsignedqword 10y ago
Does anybody really know why JS's type system was designed the way it was? It seems so out of whack with what people want out of a language, dynamically typed or otherwise.
- throwanem 10y agoIt wasn't; the language was implemented from scratch in ten days.
- mherrmann 10y agoThat explains a lot. Source for others that are interested: https://www.w3.org/community/webed/wiki/A_Short_History_of_JavaScript https://www.w3.org/community/webed/wiki/A_Short_History_of_J...
- deleted 10y ago[deleted]
- bhrgunatha 10y agoObligatory - https://www.destroyallsoftware.com/talks/wat https://www.destroyallsoftware.com/talks/wat
- curveship 10y agoIt's because Eich was told to make JS C-like. In C, an empty array, an empty string, 0, false and null are all the same value: a word with all bits 0. So in JS, those are all are falsy and == to each other.
- jomamaxx 10y agoI wish an empty string was not false. In 'object' terms, an empty string is still a string! It's something. I guess if you think about it from a memory perspective, it's 'nothing'. But since JS is not actually like C, I really wish "" were true.
- nv-vn 10y ago"" is actually true in C, but that's also because it represents something in memory. Consider how C encodes strings: an empty string is a _pointer_ to a 0 (or a '\0', if you want to think of it as a char). However, the pointer (being an address) is non-zero (since the address 0 is NULL).
- jomamaxx 10y agotouché
- Triave 10y agoIn C, empty strings are truthy, being a non-null pointer to a NUL character. Depending on what you mean by "an empty array" that might also be a non-null pointer to a zero-length region of memory, and thus also truthy in C.