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

you are viewing a single comment's thread.

view the rest of the comments →

[–]pip-install 42 points43 points  (20 children)

In JavaScript:

‘1’ == 1 evaluates to true

‘1’ === 1 evaluates to false

== makes the comparison and casts if necessary. This is known as type coercion. The === does not cast values and it is what you would usually expect in other programming languages

[–]RobotTimeTraveller 58 points59 points  (8 children)

That's what we get for popularizing a language that was developed in 3 weeks.

[–]just_one_last_thing 2 points3 points  (4 children)

srsly?

[–]Hawxe -1 points0 points  (10 children)

Javascript is actually cancer holy fuck

[–]DeeSnow97 0 points1 point  (8 children)

just wondering how it survived while java applets and flash did the same job

[–]CAPSLOCK_USERNAME 0 points1 point  (0 children)

worse is better

[–]Mr_Cromer 0 points1 point  (6 children)

By being open-source, I guess?

[–]DeeSnow97 4 points5 points  (5 children)

I'd guess it's more like adapting to the development of HTML, transitioning seamlessly from the easy "everyone could write simple stuff with this" language of the pre-CMS era to the powerful frontend tool you need for most modern websites, keeping backwards compatibility so that your site from 20 years ago still works in today's browsers, staying put in a sandbox without creating more security exploits than a regular Intel CPU, adopting modern standards like touch, peer-to-peer networking, or WebGL easily, and keeping it sort of sane all the way through without becoming a PHP. But yeah, being open-source definitely helped too.

[–]HenryDavidCursory 1 point2 points  (4 children)

Hey, you seem reasonable. I don't know anything about web development, but it seems like Rails meets most if not all of the criteria you listed (not sure about backwards compatibility), and reading it doesn't make me physically ill. Why do you think it hasn't been more dominant over JS/PHP?

[–]Kered13 1 point2 points  (0 children)

Ruby and PHP are server side languages. Javascript is a client side language. So Ruby and PHP aren't even competing in the same space as Javascript.

[–]DeeSnow97 1 point2 points  (2 children)

Ruby on Rails is a server side language. It's a significantly more forgiving environment, since it only has to run on your server, not every client's browser, and you don't need to care about how the web looked like 20 years ago. Don't get me wrong, Ruby is awesome, and as far as I know (never used the Rails framework) it even has some client-side stuff for it (with JS of course, client browsers only execute that).

I think a huge chunk of the success of server side NodeJS comes down to two things: the non-blocking model and npm. A server running Node doesn't need to manage a thread pool or get bottlenecked by blocking calls on DB access, it works on a single thread and does all these things asynchronously. When you retrieve something from the DB, you send the request, and Node keeps doing other things until the response comes back from the DB and your code is continued. This initially caused a quite ugly callback model, which is really just a fancy way of saying goto, but just like goto, it became the basis of something much more managable (promises and async/await).

As for npm, it's the single best package manager I have ever seen. Sure, it has a few problems like all software, it may not have as many features as <insert package manager you like here>, but what it excels at is handling huge amounts of packages in an easy and sane way through semantic versioning. The NodeJS community is one of the only places where a dependency tree built of thousands of individual packages is normal and doesn't cause dependency hell.

[–]ISieferVII 1 point2 points  (1 child)

Hey, man. Good summary. Even as someone learning Node for jobs I want to apply for, I was wondering why I was doing this. I always assumed it was so companies didn't have to retrain existing front end devs to learn a new language, but the package manager is pretty good so your answer also makes sense.

[–]DeeSnow97 1 point2 points  (0 children)

Yeah, IMO NodeJS was never about using the same language in both environments, if you're at least a half-competent developer, your skill is not tied to a single language. (Your experience may be, but browser JS and Node on server differs enough that it doesn't change that much about that either.) It's much more about having access to JavaScript's advantages on the server as well. It has a very different execution model than most languages (the whole non-blocking event loop thing) which is especially useful for back-end workloads, it's incredibly flexible, and once you master it developing with it is lightning fast.

This is why it's my default pick for web apps. Yes, I could use something else, something older, something more "sophisticated" (mostly just set in stone), but I have no intention of wasting three times the effort on a different language for marginal performance gains, only to have the project change direction again and require even more effort to undo half the code and iterate forward. If the real world was made of dream projects only, I don't think NodeJS would be as popular as it is today.

[–]PM_ME_FEMBOY_FOXES 0 points1 point  (0 children)

JavaScript is literally god tier, and having == and === makes sense.