Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've been coding in JavaScript for a while now and am fairly familiar with some of the more advanced coding features of the language (closures, self-executing functions, etc). So my question is, what advanced books/blogs/or anything else would be recommended to help tighten up my coding style?

For example, recently I was coding something similar to:

var x = ['a', 'b', 'c'];
var exists = false;
for(var i = 0; i < x.length; i++){
    exists = x[i] === 'b' ? true : exists;

But found that the following condensed code would work better:

var y = {'a':'', 'b':'', 'c':''};
var exists = 'b' in y;

Both store the same value in 'exists', but the second is less common, but much cleaner. Any suggestions for where I should go to learn more tricks like this?

Edit: I recently found this blog with a lot of good detail on the intricacies of JavaScript: http://javascriptweblog.wordpress.com/

share|improve this question

closed as off-topic by gnat, GlenH7, World Engineer Sep 16 '13 at 22:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – gnat, GlenH7, World Engineer
If this question can be reworded to fit the rules in the help center, please edit the question.

You might find some good answers here: stackoverflow.com/questions/2389320/… –  Andrew Arnold Feb 4 '11 at 20:36
As far as I can see some of the current answers dont seem to exactly match your intended question. I think "coding style" might give the impression that you are interested in code-formatting, naming conventions etc. (maybe emphasize on "clever tricks") Also you could make your background a bit more clear. –  FabianB Feb 4 '11 at 22:45

2 Answers 2

I've found Douglas Crockford's information about JavaScript to be very useful: http://www.crockford.com/

JSLint is useful as a tool to help enforce good behaviors, but it won't point out new optimizations like you were asking about: http://www.jslint.com/

share|improve this answer
I've read(and practically destroyed my first copy with highlighting) JavaScript The Good Parts, and use JSLint on a daily basis. I've not checked out his site yet though, I'll see what I can find over there. –  wml653 Feb 4 '11 at 21:01

Read Code!

Try to inspect some code that you can find. Try to think about good and bad parts of that code for yourself. If you want you can compare what you find with what you have learned in books, or use the book as a guide to read the code.

Try to read as much code you can, and think about what is good or bad. Maybe you find ideas to improve your own code. It is important to understand why certain things are considered good or bad.

share|improve this answer
I'd say I'm past the point of wandering the web looking for JavaScript to read. I'm a professional programmer and a large portion of my job is to read JavaScript and re-factor it. I spend hours a day unobfuscating code and reading through it only to see how poorly written it is, even in enterprise JS solutions. I've read the code behind jQuery, prototype, etc. I'm asking have you found any useful resources to fine tune your skills, above and beyond the common 'read code'. –  wml653 Feb 4 '11 at 21:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.