Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you're already a decent enough developer and just need to get your grips on JavaScript, I'd say that most books listed aren't that useful. A decent enough online reference will get you going and after that you'll have to consider that JS is a pretty large dung heap by now where you probably won't get a lot of mileage out of inhaling dust from the crusty parts. Unless you're an enterprise developer tasked with maintaining your company's Dojo application.

If you're a new developer coming into JS from a more tabula rasa situation (possibly these days), I'd still say that most of those books are wasted, and you'd probably get a better mileage out ouf SICP or the GoF book than most Ninja/21days/Dummies tomes.

The core of JS is small enough, and the rest is highly dependent on your task, scope and framework. No jQuery book will help you with your intranet extjs app or your state of the art fluxified React SPA. You'll have to wade through code to get there, preferably as much of your own as possible.

And the most important thing: Pick something and stick with it. No mid-project framework/build tool/library changes. Even "obsolete" tech still works better than falling into the Duke Nukem hole. So don't get nervous about still using "grunt" when all the cool kids are using "gapoodle".



For the decent developers picking up Javascript, http://learnxinyminutes.com/docs/javascript/ is hard to beat. All the basic syntax and language features in one page without trying to explain to you what a while loop does.


This made me gag, years ago:

  // Statements can be terminated by ;
  doStuff();
  
  // ... but they don't have to be, as semicolons are automatically inserted
  // wherever there's a newline, except in certain cases.
  doStuff()
  
  // Because those cases can cause unexpected results, we'll keep on using
  // semicolons in this guide.


I haven't gotten much into Javascript yet, but is there any reason I would not terminate with semicolons? Without understanding which "certain cases" won't have them inserted automatically, relying on that feels like asking for trouble.


As a general case I recommend always terminating each statement with a semi-colon. Then it is explicit to the interpreter and other coders (and "other coders" includes "you six months later when you've forgotten most of what you did today") that you intended this to be the end of the statement and the next line to be the start of a new one.

Only ever leave the semi-colon out at the end of a line when you are explicitly using a multi-line statement to make your code more readable.

This makes your intent unambiguous in both cases; to the interpreter/compiler, to other tools, and to other humans.


My understanding is that the original decision was to make life easier for the programmer: if you forget, we'll put one in there for you. Myself, I'd rather be told that I made a mistake, then have it ignored, because how does the compiler know what I really wanted?

Here's a good one: http://stackoverflow.com/questions/18986144/javascript-compi...

Instead of being told there's some problem with the code, it inserts a semi-colon into an arguably ludicrous location, and then gives you a differen error.

Would probably make compiler writers' jobs easier if they just spit out errors.


The actual reason that third function compiles, and the fourth does not, is that

    {
      x: 0
    }
is a block statement with a label x. Try it in your console, it returns 0. The last one is an object literal outside an expression, which is a syntax error.

In addition to that, the return statement is 'restricted production' where the line break itself is a terminator, this has nothing to do with semi-colons or ASI.


> Would probably make compiler writers' jobs easier if they just spit out errors.

If this is your preference, JSLint has you covered. Really, every JS developer should be using a linter and tweak it to fit their coding preferences.


Coming from a mostly C, Java and Perl background, I've got no personal issues with semi-colons, and often find myself adding them in languages where they're completely unnecessary, especially when switching back and forth.

Having said that, your argument could also apply to operator precedence and parentheses. Yet most languages implement this, and most users don't add them unless they're in doubt (more often with e.g. logical operators than arithmetic ones).

The rules aren't that complicated and the corner cases are (IMHO) a bit overrated. The way I see it, the more pressing reason would be the accepted JavaScript style, just like the positioning of braces.


I don't, simply because I don't need to. I'm aware there are edge cases to that, but they're usually edge cases caused by doing very odd things.


Ah, the "minify" bug: forcing people to put statement separators into a line oriented language.

Think of semicolons in JS like colons in BASIC: they let you stack multiple statements on a line. Then, go learn what the language REALLY thinks is the end of a statement, which is not "I put in a semicolon".

Too bad JS doesn't use (an explicit) backslash for line continuation, rather than guessing when a line/statement was done :-(


Missing semicolons have more pitfalls than just minifiers being naughty.

  return
  someExpression
will parse out as:

  return;
  someExpression;
and you have assumption of function call in

  x = y
  (z).whatever()
which parses out as

  x = y(z).whatever()
Nothing hint or lint wouldn't catch though. IMHO, you really need to be special to avoid explicitly writing out semicolons, but to each his own. I can maybe give it a point for unique style. :)


Only evil people put their return value on a second line...

Regardless:

http://blog.izs.me/post/2353458699/an-open-letter-to-javascr...

Although to be fair:

http://benalman.com/news/2013/01/advice-javascript-semicolon...


Wow, I got schooled. Did not realize rule 4 about lines starting with array subscript brackets or function argument parens. (regardless of the line's intent of perhaps being an array literal or simply starting with an expression to be evaluated early)

The sad reality, taking the second link to its satirical conclusion, is that all JS should be written on one line, with semicolons between statements. No guessing about the effects of line breaks if there aren't any. "I say we take off and nuke the entire site from orbit - it's the only way to be sure." :-)


While I favor Ruby/Python syntax, I'm impartial about semicolons. There are bigger battles to fight! For example, heretics who use comma-first arrays.


How would semicolons have prevented the first of those misunderstandings?

-- Don't get me wrong, those are good cases to know what is going to happen. But I think you are making the case that semicolons provide a false security blanket, since the language can complete a line you meant to wrap, or, alas, merge 2 lines you meant to have separate.

I think shell (and a few other languages) actually got it right: 1 line = 1 statement, unless there is an explicit continuation.


You might be right in that it technically is the best approach, but pedagogically the value of starting with a more specific jQuery, or Rails book is that it's just more fun to build something that immediately does something that you can see and play around with, especially if you can do so right within the browser.

Of course, it's not a good thing to stop there, but in my experience it often acts as a gateway for beginners to start actually learning 'proper' programming.

My brother, for example, has been working through the Rails tutorial, and already he's starting to read more general ruby books, doing javascript tutorials, and thinking about building a game for the browser using Rails as a backend. Plus, he'll be able to make money much sooner this way, which is a great incentive for him to keep at it.


I disagree with the last point. If you can make sure that the change is worth it, that you understand the new technology very well, and if you make a commitment to follow through and do all the necessary work, you wont fall into the "Duke Nukem" hole.

(The problem of course is that often times we don't take the time to make the necessary evaluation and want to make a change just for the sake of learning the new shiny)


I'm talking about the beginning JS programmer. So it's quite likely that they don't understand the technology they're currently working on and thus have bigger problems evaluting the new one, as there's no good point of comparison.

Also, I hope that the first project a JS newbie does isn't a 100'000 line app, but something more bite-sized, and thus you really don't have to wait months to get to use the new stack or tool. Quite often this kind of decision making happens when the project is 80% done and you have to face a few things that aren't that easy or your code has become a bit too complicated. And yes, the new tool could solve that and you might even end up re-implementing bits and pieces of that. This might not be the most effective use of your time, but it's a good learning experience.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: