Recs.
Updated
Node.js is a server-side runtime for the JavaScript language intended to be fast and light. It fosters numerous open-source projects and is maintained by a Technical Steering Committee composed of core contributors.
SpecsUpdate
Pros
Pro Runs on both the browser and the server
With Node.js, it is now possible to run JavaScript as a web server. This would allow you to be able to create server based applications sooner than would if you had to learn a separate programming language as well for server side code.
As JavaScript is the only language supported by web browsers it puts it in the unique situation of being the only programming language that's available on both the client side and server side.
Pro Massive ecosystem
JavaScript has one of the largest programming ecosystems, as shown by the being the most popular language for projects on GitHub. As there are so many projects written in JavaScript there are lots of libraries available to build off of and many of them are written to be easy to use and integrate into other projects.
There are also lots of resources available for learning JavaScript. Other than traditional tutorials, language learning sites such as Codecademy have JavaScript courses. The Mozilla Developer Database also serves as a great resource for learning about the standard libraries built into JavaScript.
Pro Functional
Most of the other languages you'll use for this is object oriented, which is fine, if you think that way. JavaScript is better at being a functional language than it is at being object oriented, which is great if you think that way. At the same time, it's a more useful functional language than Haskell, which is obsessively functional.
Pro Easy to build an application
By using the UI capabilities in HTML and CSS you can develop substantial applications with graphical interfaces more quickly and with less effort than in other languages which would require you to learn a windowing library.
Building a useful application is one of the best ways to learn a new language and because of the low learning curve for creating applications you can create more substatial programs and learn more practical programming priciple faster.
Pro No installation required
If you run a web browser you already have JavaScript installed and can get started right away. Modern browsers such as Chrome also have very powerful programming consoles built into them.
Aside from the browser console, you can also use online Javascript playgrounds such as JS Bin and JS Fiddle. Even from a tablet.
Pro Several Platforms to use the web stack and JS to create multi-platform apps
Opens the door to native application development as well as just websites. Use with React Native, Weex or Quasar (Vue), PhoneGap or Cordova, NativeScript... (etc) to build native apps. Use mostly the same code base for multi-platform and web.
Pro Prototype based Object Oriented System
Being object oriented, it supports the predominate and powerful programming approach. Being prototype based, it provides an intuitive approach to OOP. Whereas other popular languages use classes, which focus on thinking in the abstract, Javascript's prototypes allow you to focus on thinking in the concrete.
For example, in a prototypical language, you think of a rectangle, and define it. You now have a rectangle. Let's say you want a red rectangle, you copy the rectangle and give it the property red. Want a blue one? Copy rectangle again give it a blue. Big blue rectangle? Copy blue rectangle and make it big. In a class-based language, first you describe a rectangle, describe a red rectangle as a type of rectangle, describe blue and big blue rectangles, and now that you have described them, you must create instances of them, and only then do you have the rectangles. Essentially: Classes are factories for objects, prototypes are objects themselves, and the latter method was created to be more intuitive, which is particularly advantageous to beginners.
Pro First-class functions with lexical closures
While certainly not the only language with these features, this pro alone is so powerful that it compensates for most of JavaScript's problems. You'll learn to use closures and higher-order functions well in JavaScript, because you have to. And then you can generalize this knowledge to any other language that has these, and the good ones do.
Pro Integrates very well with UE4
Coding an immersive 3D game can retain the attention of new programmers. ncsoft/Unreal.js.
Pro Atwood's Law "Any application that can be written in JavaScript, will eventually be written in JavaScript"
May also be a con.
Cons
Con Complex
JavaScript has a long litany of warts and gotchas. JavaScript will bite you if you're just a wee bit careless. You have to exercise a great deal of caution and awareness. You either have to know the entire 545-page ES6 spec to avoid them all, or use a linter to help restrict you from using the bad parts (and you still have to be familiar with the language), but beginners don't know these things. (Linters are also prone to time-wasting false positives.) This is a significant cognitive burden on even the experienced programmer (as if coding wasn’t hard enough already), but try learning to program in the first place on top of all of this and you'll understand that JavaScript is a terrible choice for the beginner.
Con Counter-intuitive type conversion
JavaScript is rather inconsistent when dealing with different types. For example, when working with the + operator and two numbers, they will be added, two strings will be concatenated:
3+5; // 8;
"Hello "+"world"; // "Hello world"
When using +
with a string and a non-string operand, the non-string operand is converted to a string and the result is concatenated:
"the answer is "+42; // "the answer is 42"
"this is "+true; // "this is true"
In any other case (except for Date) the operands are converted to numbers and the results are added:
1+true; // = 1+1 = 2;
null+false; // = 0+0 = 0;
Con Does not teach you about data types
Since JavaScript is a dynamically typed language, you don't have to learn about data types if you start using JavaScript as your first language. Data types being one of the most important concepts in programming. This will also cause trouble in the long run when you will have to (inevitably) learn and work with a statically typed language because you will be forced to learn the type system from scratch.
Con Numbers that begin with 0 are assumed octal
This is very surprising for beginners. Especially since 00
through 07
seem to work just fine. And this isn't just for hardcoded numbers. The parseInt()
function has the same problem, but only on some systems.
Con Good tools are pretty much a MUST for new programmers
You really want to be using a good editor (light IDE) and a linter, type checker (e.g.:Flow), etc. until you grok the language. And choosing / setting-up that development environment is it's own learning curve. If taught in a classroom, using a subset of JS with solid tools, there is an argument that JS could be an ideal first language... however, that is a lot of ceremony to protect the new programmer from JS gotchas. But without the tools, JS can be a very painful painful first language (trying to figure out why your code isn't doing what you intended).
Con Limited standard library
Much often needed functionality is not in the standard library. (Contrast with Python.) However, there are well established libraries such as Lodash, to fill the gap (however, due to the diverse/fractured ecosystem it may not be clear what library to use).
Con No "clear choice" frameworks/libraries
The closest JS gets (IMHO) is jQuery for consistent DOM api. From libraries to fill the hole left by no comprehensive standard library (eg: lodash, underscore, ramda, functionaljs, sugar, core-js, stdlib, locutus, or the N implementations of range or pad on npm), to front-end frameworks (angular, aurelia, vue, react, ember, polymer, etc), and everything in between; the JS ecosystem is hugely diverse and there is rarely a "major" library or framework for a given purpose.
This is overwhelming for a new user. While diversity is good, at least having a major/primary library/framework for a given need/use is highly desirable for a "learn this first"language in order to be productive and focused (not to mention finding fast and accurate help from the community).
Recommendations
Comments
Flagged Pros + Cons
Con No type safety
Type safety allows the compiler to check the object type and finds programming mistake. As server-side programs become much larger than client-side programs, a strongly typed language helps to keep the code clear and bug free.
Con Poor conventions and standards
Node.js has suffered from failing to standardize around a single set of conventions for pretty much everything related to the asynchronous code it's designed around, from callback parameters to Promise implementations to modules to error handling conventions. This, combined with the lack of a type system and generally insufficient documentation means a lot of time gets sunk into tracking down runtime errors and writing wrapper code.
Con Regular abuse of mutation and the 'this' operator
It's not uncommon to run into situations where just lambda-lifting some definition subtly breaks your server.
Con Weird type coercions
'5' - 1 == 4
, but '5' + 1 == 51
. There are other examples that make even less sense.
Con Fake object orientation
JavaScript pretends to have objects but actually only has hash tables and a function data type. This is ruinous for developers expecting real OO design.
Con Difficult to configure; Relies on boilerplate
Without boilerplate, one need to manually setup tens of dependencies for a production-ready javascript project.
Con Hipster community with a serious case of ADHD
The JavaScript community is constantly rewriting, reinventing, and reworking things to "fix" the myriad shortcomings of the JavaScript language and ecosystem. All this churn is in vain and does little to improve anything.
Con Easy to fall into bad manners and bad mind structure
It wouldn't consolidate a good mind structure for moving to other languages. Too open.
Con Asynchronous coding is not easy for beginners
JavaScript can work synchronously but its current use is mainly around asynchronous instructions, and it's surely not a good way to start learning programming.
Con Inconsistent operators
Given "" == 0
is true
, and 0 == "0"
is true
, therefore "" == "0"
is false
. What?
Con Dependency on browser developer(s)
JavaScript is a language that is ran inside of the browser. Because of this, you are limited to what the browser can do. Sometimes they even have different functions to accomplish the same thing! A great example of this is the following:
This works in Chrome and IE:
document.getElementById("foo").innerText;
And this works in FireFox and Chrome and IE:
document.getElementById("foo").textContent
You're also unable to use some of the less-popular CSS3 features in one browser versus the other. Can't give a detailed list due to ongoing development.
Con Each browser has its own quirks when executing the same code in some cases
Beginner programmers often make the mistake of coding something, seeing it works in the browser they tested it in, and then scratching their heads when it doesn't work in another browser. Ideally you'd want a language that works consistently across all platforms in order to be able to focus more on the programming and less on the underlying environment. It just takes time away from learning and forces you to spend time figuring out why this worked in browser X but not browser Y.
Pro Interactive
JavaScript allows webpages to be more interactive, with the ability to function well without needing to re-load the entire page. Users have a better experience when filling out information if they get feedback on fields they are entering in real time, instead of submitting a full page of fields before getting an error message.
Out of Date Pros + Cons
Con Easy to accidentally use globals
If you forget a var
or new
, you can clobber the global scope. For tiny scripts (JavaScript's original use case), globals are great, but for larger applications, globals are generally regarded as a Bad Thing. This is because changes to one small part of a program can randomly break things anywhere else. These kinds of bugs are notoriously hard to find.
Con The `null` and `undefined` objects aren't really objects
Therefore, attempts to call methods on them will fail. This is especially frustrating since these are often returned instead of throwing exceptions. So a failure may appear far away from the actual cause, which makes bugs very hard to find.
Con Array-like objects
Many cases when you should get an Array, you just get an Array-like object instead and none of the Array methods work on it.
Con Many tutorials, code, and resources, are structured for older ES5 code
Con Unclear story for scaling
While there are some big stories about NodeJS there is no huge business running its prime service on it.