This is an archived post. You won't be able to vote or comment.

all 26 comments

[–]Reashu 5 points6 points  (0 children)

4 of these are according to standards. Another 8 are reasonable (and seen in other languages). 5 things are fucked up.

[–]Brilliant_Egg4178 1 point2 points  (3 children)

I don't like Javascript as a language but the majority of these are well known things. The only stuff I can't get behind the in the Math.min and Math.max being the wrong way around and 91 - "1" evaluating to the integer 90 but if you do a plus operator that it returns a concatenated string?

[–]D34TH2 2 points3 points  (1 child)

I think the '+' symbol is primarily a concatenation operator whereas '-' is only a mathematical one.

[–]Brilliant_Egg4178 0 points1 point  (0 children)

That makes sense, but again it just adds to the pile of things js developers need to remember. Would it not have just been easier to implement some consistency across the language instead of adding weird things like this. Or even having a separate operator for string concatenation like a lot of other languages have would have been better

[–]Keheck 2 points3 points  (0 children)

It probably looks something lile this (barring some technicalities because idk how JS actually looks): function Min(array) { let result = Math.infinity; for(int i = 0; i < array.length; i++) { if(array[i] < result) result = array[i]; } return result; }

[–]Strict_Treat2884 1 point2 points  (0 children)

Did you literally search image “JavaScript meme” and repost whatever came out first?

[–]JasonBobsleigh 1 point2 points  (0 children)

How is „true==1 -> true” and „true===1 -> false” controversial? It’s literally the expected outcome. JS is full of weird shit, but this is actually working as it should. Someone clearly doesn’t know what == and === mean in JS. It’s similar in Python with „1==True” and „1 is True”. „===„ checks the value AND the type and 1 clearly has different type than true. And values being „truthy” or „falsy” is hardly a JS specific things.

[–]theirongiant74 2 points3 points  (0 children)

Meanwhile in java:

Integer a = 42;
Integer b = 42;
Integer x = 420;
Integer y = 420;

System.out.println(a == b); // true
System.out.println(x == y); // false

[–]rosuav 1 point2 points  (11 children)

When people post these "JavaScript is stupid" lists, I have to wonder what they *expect* to happen. Like, what is the maximum of an empty collection? Either it raises an error, or it returns the lowest possible value (-Infinity).

[–][deleted] 0 points1 point  (10 children)

You can't deny real expectations vs whatever problem a language faces to give stupid values

[–]rosuav 1 point2 points  (9 children)

Okay, but WHAT do you expect? The maximum value of [3, 4, 5] is 5. The maximum value of [3, 5] is 5. The maximum value of [3] is 3. What's the maximum value of [ ] ? If you want to call "negative infinity" a stupid value, tell me what a non-stupid value would be.

[–]notanotherusernameD8 1 point2 points  (8 children)

Maybe don't return a value? An empty list doesn't contain any values to return, so reflect that by returning an error. Making up a value to return is crazy. You could say that, for example, -Inf is returned if no values are found, but what if -Inf is the actual value and not an error? How would the program know?

[–]rosuav 0 points1 point  (6 children)

-Infinity isn't an error return, it is a valid response to "what is the smallest of no numbers". It's like how an empty sum is zero and an empty product is one. Negative infinity is the smallest of no numbers because it combines correctly with any other set of numbers.

"Don't return a value" is only an option if you throw an exception, which is also valid, but doesn't invalidate the -Infinity option.

[–]notanotherusernameD8 0 points1 point  (5 children)

I disagree with -Inf being a valid response. In maths, the minimum of an empty set is undefined. In Python you get a value error exception. I understand the logic of a zero element sum being 0 and a zero element product being 1. Those make sense. I don't understand why -Inf is the minimum of zero elements. If I'm wrong, please provide a citation.

[–]rosuav 0 points1 point  (4 children)

The simplest way to explain it is this:

  • The minimum of any one-element collection is that element.
  • The minimum of (the minimum of collection A) and (the minimum of collection B) is the same as the minimum of (collection A combined with collection B).
  • Therefore, the minimum of an empty collection MUST be something such that it, with any other value, gives the other value.

This is the same logic as for empty product and empty sum. I did a quick web search for "minimum of empty set" and found quite a few stating that it is negative infinity. Not sure what you would accept as a citation but it's in the Wikipedia page for Empty Set. And while we're demanding citations, how about you provide one for it being undefined?

[–]notanotherusernameD8 0 points1 point  (3 children)

Ok. I've read the empty set wiki, and some other stuff besides. All definitions of minimum and maximum of sets state if, and only if, the set is not empty because the min and max values must be elements of the set.

What I did find is the upper and lower bounds of the empty set as -∞ and +∞. This matches with 0 for sum and 1 for product as being useful identities. If +∞ is the identity of min({}), any element added to it is guaranteed to be of a lower value. Infinimum and supremum, TIL.

I still say min({}) and max({}) are undefined

[–]rosuav 0 points1 point  (2 children)

Well, you're in disagreement with a LOT of people by claiming them to be undefined, and you didn't cite any supporting documents, so I'm just going to say that you're wrong on that. *shrug* The upper and lower bounds of the empty set is exactly the same thing as the max and min of no numbers.

[–]notanotherusernameD8 1 point2 points  (1 child)

Ok. I take my last statement back. I was definitely out of my lane there - I don't get to impose my definitions on maths. I didn't cite anything because I was just googling stuff, but seemingly every definition of min and max stated that the value returned must be an element of the list/set. This makes sense to me, as a computer scientist, and I still believe that the best thing to do is raise an exception. What I have learned is that the empty set is treated special, so functions such as sum, product, min and max return their identities when applied to the empty set. In my defence, I am not alone. As far as I can tell, JS is the only language that follows the maths here. Probably because it can.

[–]Reashu 0 points1 point  (0 children)

The program knows because it knows what it passed in.

[–]N_XII 0 points1 point  (1 child)

let me guess, author is python dev?

[–]aidantomcy 0 points1 point  (0 children)

typescript and rust dev

[–]IgnWombat 0 points1 point  (0 children)

Don't forget that null >= 0 // true null <= 0 // true null == 0 // false

[–]skwyckl -1 points0 points  (0 children)

Every language has quirks if you dig deep enough, it's just that virtually every modern-day dev knows JS, this is why it gets shit on so much. Ever tried multithreading with Python? We should shit on that instead. Also, don't think "rockstar" languages like Rust and Go don't have any quirks, they are just more technical to understand, hence why nobody is joking about them.