What other programming languages do this?
What other programming languages do this?
Other urls found in this thread:
destroyallsoftware.com
twitter.com
Why do the first few lines end with semicolons but the rest dont?
pajeet pasted code from multiple answers on stackoverflow
i didn't believe
i cannot believe it
why the hell is javascripts sort function broken?
It's sorting alphanumerically, not by integer value. 1 is followed by 10, then 20 then 5
var i = "1"; i++; //11
Who would possibly think this is a good idea?
why is that the default?
It's because if you had an array that *might* contain a string but won't certainly, then the sort function would get all out of whack when there isn't a string but you want it sorted alphanumerically. To sort numbers as numbers, you just tell it how to compare them:
[5,1,20,10].sort(function(a,b){return a>b})
I have no idea
Multiple commands one line motherfucker
It's not actually true though
because the toString() function is called when you add them, in case you need operator overloading in JS.
first line irritates me the most.
what does
var i = "a"; i++;
result in?
First 2 lines are operations, sort returns a value, and the rest are expressions.
1 + "1"
12.000000000 == 12.000000009
>>True
this is the power of JavaScript.
NaN != NaN is IEEE754 spec
typeof NaN === "number", what else should it be?
I just got rused didn't I
it has no real types
Why does string even have a ++ operator?
How often do you need to double a string?
Yep, I was referring to this:
```
var i = "1"; i++; //11
```
this is not correct
It doesn't; i++ coerces into a number first
Which is still silly but in a different way
>Not a Number
>Is a number
pick one
Only static kiddies need their type crutches to keep track of variables. It's not hard at all to avoid edge cases.
I don't know. I only work with real languages, which are strongly typed or treat all datatypes as strings (erlang)
var x = "1"; x++;
1
x
2
am I missing something?
NaN
[5,1,20,10].sort((a,b) => a>b)
typeof "this is not a string" === "string"
Where's your god now?
>using == instead of ===
This is bait.
>i = "1" // this is retarded
>typeof NaN // had better be number
>NaN !== NaN // so many bugs would slip through unnoticed otherwise
>abusing == // only pajeets do this
![] == [] // true
何
arrays aren't truthy or falsy, even empty ones.
[] == true // false
![] == true // false
Javascript is excellent to filter shitty programmers, a person who trust types directly in a dynamic language is shit, the solution is easy: parseFloat or *1.0 , parseInt *1, and +""
>>abusing == // only pajeets do this
>only pajeet uses the == operator
you heard it here first Sup Forums
this an isNaN
Fuck off discordfag
In js, you use === for all equality checks except very rare cases where it's maybe tolerable, like == null which handles also checking for equality with undefined
NaN! ?!?!??!?!?!
You're already an exception.
>What other programming languages do this?
I assume what you mean is, "What other programming languages allow idiots to write shit code?"
The answer to your question is, "All of them."
remember kids. always use strict comparison operator
PHP?
My fave JavaShit:
['10','10','10'].map(parseInt)
['10','10','10'].map(i=>parseInt(i))
which part? + being overloaded for concatenation and adding? + coercing the string into a number? NaN being funky? Falsyness of various things? Automatically insert semicolons?
>too fucking retarded to know the signatures of parseInt and map
>that sort function
does this happens when using an array already in a variable or something? mist other things are at least excusable, but this is outright broken. someone somewhere probably wasted at least a night over this.
sorted alphabetically
*most, i can't type for shit
but why. it's an array of integers, i don't give a fuck if your sort function works for every type under the sun if it doesn't for fucking integers.
What happens if there's a element that's not an integer than you fucking idiot?
I'm learning Java in college right now as part of my network/telecom program. It's my first time ever learning a programming language, and so far I'm enjoying it.
My only worry is I kind of would rather learn a more commonly used language. Am I wasting my time or is Java similar enough to more commonly used languages that once I become confident in it I should be able to learn other languages more easily?
semicolons are optional in javascript :^)
Java is THE most commonly used language.
Just a reminder to everyone that true > false
I thought it was being pretty much phased out for computer applications, but thanks for letting me know otherwise
Sure. And to answer your other question, it's very easy to learn a 2nd language after learning a first. (Though you should resist the tempation until youve got pretty good at your first language) Have fun!
It fucking adds it at the end of the list. How hard is it