Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Let me explain the things to you:
You defined x, and then gave it the value of x, which was `undefined`.
x++ is a macro for x= x + 1, undefined is not a number so it gets converted to NaN, and added 1.
NaN is a "number" primitive value, just like Infinity, which you can't do most operations on.
====
0 == !"0"
Alright, intrepreter first converts the "0" to a boolean, the string is not empty, so it's true. Not'ted and `false`.
0 is a falsy value, so you compare "false == false"
0 == "0"
left side is number, right side is string, let's make a number from "0", which makes 0.
0 == 0 is true.
0 === "0" wouldnt be true because you also compare the types and block implict conversions. -
ltlian21963y@melezorus34 oh, I know why they happen. That doesn't make the implicit behavior less of a meme.
At no point would I want to do this without error or warning, but there's nothing stopping you from incrementing global or bitshifting an empty array into window. -
@ltlian If it's a meme, tag it as such. Ranting on language features that lie as basis for the language itself is just being dumb.
@melezorus34 Not entirely correct regarding the ++, but close enough I guess... -
@ScriptCoded why is it dumb to rant about the fundamentals of a language?
Because we cannot change it? Because it is how the language is? Thats exactly the reason to rant about it, imo.
Plus, it’s funny. It’s funny, not because we don’t know why that happens, but because we do know it and the language designer decided that it would be a good idea. Or they couldn’t see the implications at that time. That makes it funny and valid to rant about. -
Yep, JavaScript has the worst autocasting.
It is like someone had rolled dice to determine what would cast to what in which situation.
If you have to do code review for JavaScript, you should consider banning any use of automatic casting. -
@ltlian @melezorus34
I think the issue is not that these examples can't be explained, but that they can be hard to spot and interpret for a developer.
The bad parts of Javascript is not caused by inconsistency -- It's actually a fairly consistent language -- It's about comprehensibility.
Duck typing is dangerous. Sure, it walks and quacks like a duck, BUT I FUCKING MEANT FOR IT TO BE A GOOSE DAMMIT.
The language might have strict, consistent rules for type conversions, but those rules must be uncomplicated and unambiguous for the developer.
In my opinion, a program should break on a less straightforward conversion/inference.
Turning an int into a float... meh, it's all just numbers. But turning a string into an int, or an array into a bool -- That should always be done explicitly. -
@Lensflare Yeah I worded that badly. What I'm trying to say is that ranting on language features and underlining that it's "a mess" and essentially implying that it doesn't make sense, when in fact it's quite logical while also stating that you know the language and why it happens - that's not very bright.
-
@ltlian man, at this mind twister
0 == '0'
0 == !'0'
I lost it 😂 It must be some sort of meme! Damn... -
@ltlian Everything about JavaScript gets weird. It has a reason but it's still weird.
-
ess3sq1633y@ScriptCoded if you understand the language and know why it happens you are in the best position possible to rent about it.
-
Lol
Try using await sometime and look at their weird ass rules from doing it from the main calling scope if you want to see a mess !
Related Rants
One of my favourite pastimes is to find ways to highlight what a mess JavaScript is.
rant
js
javascript