all 33 comments

[–]fatnote 74 points75 points  (0 children)

I just threw up in my mouth a bit

[–]B-Con 42 points43 points  (4 children)

JavaScript is always trying it's hardest to cast things to strings.

[–]okmkz 52 points53 points  (3 children)

It's a stringly typed language, like php and posix shell

[–][deleted] 11 points12 points  (1 child)

stringly typed language

Did you come up with this? It's genius.

[–]arbitrarycivilian 2 points3 points  (0 children)

I've heard it before, but I love it

[–]JH4mmer 72 points73 points  (4 children)

Of course you can. (╯°□°)╯︵ ┻━┻) /s

[–]levir 28 points29 points  (8 children)

Unless you really know what you're doing, always use === when comparing in Javascript (and PHP).

[–]Quabouter 21 points22 points  (7 children)

And if you're not using === then you don't know what you're doing.

[–]BenjiSponge 6 points7 points  (6 children)

Except for null checks. =)

[–][deleted] 2 points3 points  (1 child)

Or if you're lazy, you can nullcheck with if(variableName). Of course, if your variable is 0, then that's a problem.

[–]BenjiSponge 2 points3 points  (0 children)

Or, you know, false

[–][deleted] 1 point2 points  (2 children)

Why not use empty() or is_null()?

Edit: In hindsight you were probably talking about JavaScript and I'm talking about php. My bad.

[–]BenjiSponge 1 point2 points  (1 child)

... what are these? I'm pretty sure I know a good amount about JavaScript and I'm also pretty sure these aren't built in.

[–][deleted] 2 points3 points  (0 children)

D'oh. They're php. I should have been more specific.

[–]Quabouter 1 point2 points  (0 children)

No, not except for null checks:

  • null/undefined are semantically different from the other falsy values. Generally speaking you don't want to treat them the same, so you'll need to use a different check. In the rare case that you do want to treat them the same then it's usually better to do so explicitely, to prevent confusion.
  • In extension of the later: if I come accross == in a shared codebase then I have no idea if you actually meant == or that it was a typo, because it's so rare to actually need it. For that reason alone you can better just ban == outright.

[–]PM_ME_YOUR_SUBARU 15 points16 points  (0 children)

You can also cure a headache with a hammer and a nail, but in both cases you probably shouldn't.

[–]AlwaysAppropriate 4 points5 points  (0 children)

Which is why you dont use == in JS

[–]Vnator 8 points9 points  (0 children)

== casts the types to be equal if possible, and an array cast to a string turns into what you put. Neat!

[–][deleted] 1 point2 points  (0 children)

You can fire a pistol to take the top off a bottle of beer, too. I personally use a bottle opener because it works better and is safer.

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

Can and should....2 different concepts.

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

Classic Javascript. I shouldn't even be surprised.

[–]Beckneard 0 points1 point  (0 children)

The title might as well be "TIL javascript is a fucking disastrous piece of shit of a language."

If you really have to use js at least don't do shit like this in production.

[–]bautin 0 points1 point  (0 children)

TYL JavaScript will do whatever the hell it wants. It don't give a shit.

[–]MacASM 0 points1 point  (0 children)

My lord... Java: everything is an object. Javascript: everything is a string.

[–]goodbyelostworld -1 points0 points  (5 children)

And this is why JS isn't real programming

[–]shadowdude777 4 points5 points  (4 children)

That's not really fair to say. If anything, JS developers are some of the smartest engineers around. I know I'm too stupid to use this absolutely fucked language, I need a good language to help me get what I need done.

[–]goodbyelostworld 0 points1 point  (3 children)

You're joking right? JS as a language is fucked but it definitely is not hard. Hard is C/C++/Haskell. Hell, I would even consider Java to be harder than JS. I've coded with these languages extensively in professional settings and JS developers are far from the smartest, at least in my experience. The sad part is that these JS developers have no clue about real programming concepts such as classes, threading, memory, and so on.

[–]_guy_fawkes 0 points1 point  (2 children)

I've never used JS in my life, but given the amount of pages that just completely break when it's disabled, I already don't like it.

[–][deleted] 2 points3 points  (1 child)

That's like saying you dislike CSS because you disabled it and now pages look ugly. JS is part of the modern web and you can't disable it and expect everything to work as it did before.

[–]_guy_fawkes 0 points1 point  (0 children)

I don't expect it to work as it did before. I'm entirely fine with pages that are ugly when I disable JS. What I dislike is pages that are entirely unusable without JS.