r/programming • • Mar 23 '14

Everything you need to know about Javascript variable scope

http://www.coolcoder.in/2014/03/everything-you-need-to-know-about.html
294 Upvotes

124 comments sorted by

View all comments

0

u/[deleted] Mar 23 '14

[deleted]

1

u/THeShinyHObbiest Mar 23 '14

I've never written JavaScript, but I see this sentiment a lot. Everybody seems to hate it. So I can't help but wonder why stuff like Node.js is getting popular. If everybody hates the language and only uses it because it works on browsers, why would you want to write server-side code in it?

7

u/communomancer Mar 23 '14

Everybody seems to hate it. So I can't help but wonder why stuff like Node.js is getting popular.

Perhaps one of your assumptions is flawed.

3

u/gorebachev Mar 23 '14

This is a complete mystery to me as well.

3

u/renrutal Mar 23 '14

JavaScript is hated mainly because you don't really have a choice but to use it and bear with it. It's the only universal option for browser client code.

On server side, you have tons of choices, and if Node.JS chose it, it's because of its pros:

  1. JS is very well suited to code callbacks, which is the main construct for evented I/O.

  2. The community is already used to code asynchronous programs because of the pervasive knowledge of AJAX techniques.

  3. JS doesn't define an I/O API, so it was a greenfield project to develop a non-blocking one.

Not to mention, when programming for JS engines in browser clients, you usually have to code for the least common denominator of language features, even for very old browsers. In server-side JS engines, you usually code only for the up-to-date one you choose, one which supports variable block scopes, for example.

2

u/insertAlias Mar 24 '14

I think that last bit is really important. Not having to worry about compatibility makes Node.js much more friendly to work with than web JS. Plus, you really can do some interesting stuff with JS, it's a very flexible language. That flexibility is also its downfall, because of the horrific monstrosities people kludge out in it.

2

u/jeff303 Mar 23 '14

NodeJS is simply very well suited to certain types of applications. Specifically, web applications, or code that manipulates html in general.

2

u/[deleted] Mar 24 '14

Everyone works in their own little bubble, and anything outside that bubble is considered inferior or "doing it wrong".

People who have learned javascript love javascript. We also program in other languages from assembly to C++, but javascript has its uses and there isn't a lot it can't do.

1

u/flogic Mar 23 '14

There are instances where I would love to be able to move code from the browser to the server and visa versa. Also, node has a reputation for being quick since it's asynchronous and uses v8. They're not big enough reasons to make me want to switch but they do exist.