Jump to ratings and reviews
Rate this book

Maintainable JavaScript: Writing Readable Code

Rate this book
When you're writing code alone, you have a lot of leeway. But when you start writing code as part of a team, you need to think harder about the decisions you make. This book will help you do that.
When you write code in a team setting, will other developers be able to understand what you did? Did you organize your code in such a way that it's easy to adapt and extend? Will your code survive once you're gone? Maintainable JavaScript doesn't just recommend a set of guidelines, it examines guidelines being used and recommended by others in the industry, so you get a feel for what's common in well-run JavaScript projects.
Save a copy of this book now. It's the only resource that focus solely on JavaScript conventions.

238 pages, Paperback

First published January 1, 2012

16 people are currently reading
495 people want to read

About the author

Nicholas C. Zakas

17 books106 followers
Chinese: 尼古拉斯

Nicholas C. Zakas is a front-end consultant, author, and speaker. He worked at Yahoo! for almost five years, where he was front-end tech lead for the Yahoo! homepage and a contributor to the YUI library. He is the author of Maintainable JavaScript (O’Reilly, 2012), Professional JavaScript for Web Developers (Wrox, 2012), High Performance JavaScript
(O’Reilly, 2010), and Professional Ajax (Wrox, 2007). Nicholas is a strong advocate for development best practices including progressive enhancement, accessibility, performance, scalability, and maintainability.

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
78 (26%)
4 stars
120 (41%)
3 stars
75 (25%)
2 stars
16 (5%)
1 star
1 (<1%)
Displaying 1 - 29 of 29 reviews
Profile Image for Rob.
Author 2 books435 followers
May 27, 2012
Maintainable JavaScript by Nicholas Zakas (O'Reilly 2012) is a short-and-sweet little text on (as the cover says) "writing readable code". And by "readable code", Zakas means "code that other developers not named [YOUR NAME] will be able to read and make sense of and ultimately maintain". It goes beyond maintainable and readable code though--Zakas takes us on a tour of how to deliver high-quality JavaScript that is testable and maximally performant in production. If you look at Zakas' catalog, this subject is right in his wheelhouse, and the book reads like either a sequel to his 2010 [title: High Performance JavaScript] or else as a lengthy appendix to an expanded version of Chapter 24 of his 2012 [title: Professional JavaScript for Web Developers] (3rd edition). It's an opinionated book about formatting style, about programming conventions, and about ways of helping you (and your team) write code that is a lot less likely to blow up on you down the line.

Right off the bat: the target audience for this book is not advanced JavaScript developers. If you are an advanced JavaScript developer (or even many mid-level JS devs) then these are concepts that you are already familiar with. You've already dabbled in a style guide. You already know to minimize global variables. You already know to use feature detection. And there's a good chance you're at least linting, if not testing, if not doing both of those things automatically as part of your build. If that sounds like you, then you might want to take a pass. But before you do, give the table of contents a second glance. (If nothing else, you'll feel really validated.)

So who is it for? It's for novice and intermediate level JavaScript developers that want to get a better sense of what "readable" and "maintainable" code looks like. It's for folks that are plowing through the other "slim" JavaScript books in the O'Reilly catalog. [1] It's for technical managers who don't have a JavaScript background. It's for folks that want to start a book club for front-end devs and have spirited debates about ASI and how many spaces to indent when an expression continues on the next line.

As I worked through Part I ("Style Guidelines"), my initial impression was that Zakas was writing a how-to for writing JavaScript style guides. We have 44 pages of in-depth discussion on where to put curly braces, how many blank lines to use (and where), and what a proper comment looks like. Esoteric rationales to inform what (on the surface) seem like so much pedestrian banalia. ("Who cares what I name my local variables?") But by the end, there is a well-reasoned case made for all of the recommendations that will go on to appear in Appendix A.

Where the book becomes more interesting is in Parts II ("Programming Practices") and III ("Automation"). Again: the chapters that comprise Part II are going to seem like review for many seasoned JS devs: keep your JS and your mark-up loosely coupled; avoid global variables; keep configuration data separate from business logic; use feature detection instead of browser detection. As much of these may seem like review, [2] don't get cocky and skim it, either--there are some gems in there. (In particular I'm thinking of the chapter on Event Handling that spawned this interesting post by Ben Nadel.)

The chapters in the Automation section were my favorites. Zakas builds up a solid Ant-based [3] build system over the course of 7 chapters that includes validation and linting, file concatenation and gzipping, minification, documentation, and automated testing. As I've become highly interested in the build process, I was riveted by these chapters. Zakas at least touched on every topic in the automation/build topic that I would have wanted to see. But that being said: the operative phrase was "touched on"--I would have loved to see more on this subject. He provides a lot of excellent starter material, and Appendix B is a rich list of other jumping-off points, but it also seemed... shallow? Like he was just scratching the surface? This seemed especially true of the chapters on documentation [4] and testing. [5] [6]

All in all? I would strongly recommend this to folks that are new to JavaScript, but only a mild nudge to seasoned folks.

------

[1] And by "the slim JavaScript books", I mean: Crockford's JavaScript: The Good Parts , Stefanov's JavaScript Patterns , and Zakas' High Performance JavaScript .

[2] Especially if you've been keeping up with Zakas' blog posts. "Don't Modify Objects You Don't Own", anyone?

[3] Although, honestly, my first thought was: "Really? Ant?"

[4] Although I suppose I have lofty expectations for documentation. (A detailed glossary of what the different @keyword annotations are for etc.) This chapter is probably fine, it's my expectations that are messed up.

[5] I definitely think there could have been more on testing. There's like a page and a half on PhantomJS. Having played around with it a bit myself, I feel like it could have earned a chapter all to itself. Granted, I wouldn't want the whole book to be about testing ( Grails in Action , I looking in your direction)--and since most JS books don't mention testing at all, I'm grateful to see it get at least the chapter that it did but... I could have used a little more.

[6] Also: Zakas implies that you need to run JavaScript tests in the browser and I just don't believe that to be so. If you're working with the DOM or BOM objects, then yes: he's right. But if you're otherwise following functional programming patterns, and have clearly defined arguments and returns, and you're avoid side-effects in your code... Well, you should be able to unit-test stuff like that without a full-blown browser at your beck and call.

------

Disclosure: I got a free copy from O'Reilly in exchange for writing a review as part of their blogger/reviewer program...
Profile Image for Ingus Rūķis.
18 reviews8 followers
August 26, 2012
Covers quite a lot about writing good quality JavaScript code. Can be used as a complete resource for implementing your own JavaScript code style guidelines as well as learning about various build tools and other important bits of modern JavaScript development. Despite the fact that I've been doing web programming for nearly a decade I found interesting and unknown bits regarding JavaScript development in this book. Recommended!
Profile Image for Max.
26 reviews1 follower
July 23, 2015
Отличная книга для своего времени. Сейчас много советов по оптимизации JS кода уже устарели
Profile Image for Igor.
97 reviews
June 23, 2017
This book is must read for every team that is working on bigger JavaScript project. The author
has that kind of experience, he worked in the development of the Yahoo page and explains what
practices should be followed in order the code to be scalable, readable and maintainable.

If you are experienced developer you may know the most of this stuff. I have experience in OO programming
but I am relatively new in JavaScript so this book helped me to understand some practices and principles
that are specific for JavaScript. In my opinion the part where the configuration for build, documentation
tools is explained can be shorten because you have the specific tool documentation for that.

If JavaScript team reads this book before beginning of the project and implements the advices and practices
written here it will have much easier job later in the project.
379 reviews10 followers
August 7, 2013
La prima parte di questo manuale è una estesa raccolta di best practices su come organizzare il codice, come suddividere gli script, come nominare le variabili, ecc.

La seconda parte copre quasi esclusivamente l'uso di tool esterni (per analisi statica del codice, raggruppamento, minificazione, ecc.) e Ant per automatizzare tutti i processi di deploy.

Se non avete mai letto manuali sullo stile di programmazione e non conoscete Ant, questo manuale è un must read, mentre se avete già basi di clean code, usate già jslint e soci, e conoscete già Ant, sarà fondamentalmente inutile.

Se avete già letto "Professional Javascript for Web Developers" (dello stesso autore) o "Javascript the Good Parts", la prima parte sarà abbastanza inutile, in quanto già coperta da entrambi, e la seconda parte potrebbe non valere il prezzo, soprattutto se non usate Ant.
Profile Image for Brian.
666 reviews292 followers
July 20, 2012
(3.5) Some helpful stuff, still preferred JavaScript: The Good Parts (though it's less opinionated than that)

A lot of it is general good programming practices, but made more explicit in JavaScript. I wish he justified all of his coding conventions. I'd still recommend reading this though.
Profile Image for Philipp.
7 reviews5 followers
August 8, 2014
Great, easy and fast read for all JS Developers, especially when working in a team and when you're working out your own JS guidelines or learning about some strange parts of the language (applies to beginners as well as to advanced JS devs). Some parts are a bit outdated (e.g. Automation with ant; grunt was probably in its early stages that time), but they are easy to spot and skip.
Profile Image for Daniel R..
219 reviews13 followers
December 31, 2016
A good checklist of areas to consider when thinking about how to write and maintain code. Alas the state of art in JavaScript mid 2016 has negated many of the concrete suggestions in the book. Likewise many tools mentioned in the automation section would not be used in a modern development workflow.
33 reviews
Read
April 14, 2014
Started off strong but overall felt very light, none of the topics were covered in any depth. (To be fair this is a pre-release version of the book). I also would have preferred the Automation section to be tool agnostic, the focus on Ant was a real shame.
Profile Image for Iman Mh.
10 reviews1 follower
September 14, 2013
This book is awesome. If you now javaScript and you want to improve your code style habits I highly recommend this book. How ever this book is written when Grunt was not so popular like it is today, so part 3 automation is not that attractive and it is covering an other tool (Apache Ant).
Profile Image for Nephi.
53 reviews
January 3, 2024
The advice is generally really sound, the problem that I had with this book is that it uses ant for the build system, grunt would have been a much better choice. If this book is aimed at java developers then maven would have been better... personal preference I guess.
Profile Image for Aaron Gustafson.
Author 16 books24 followers
Read
March 30, 2014
Any practicing frontend programmer touching JavaScript should read this book. Consider it the Strunk & White for JS devs.
Profile Image for Miguel Frias.
6 reviews
December 1, 2013
A very useful code convention for Javascript, I really recommend this book to all frontend developers, especially, to the one's that work on larger projects.
Profile Image for Andy Wang.
10 reviews
July 20, 2014
Part 1 and part 2 are worth reading, although there are some errors and typos. Part 3 is a little outdated already.
Profile Image for Fred Lin.
35 reviews2 followers
December 16, 2014
Coding style convention of Javascript.

������������ Javascript ��� coding style ������������������������������������. ��������������������� Javascript ������������
Profile Image for Michael.
22 reviews4 followers
May 3, 2015
Wished I'd read Maintainable JavaScript by Zakas years earlier. JS style guide .. code a lot less spaghetti these days!
Profile Image for Anton.
77 reviews13 followers
Read
February 18, 2016
Great book for programmers who wants to improve their code writing. It also a great guideline for group projects.
Profile Image for Georgii.
5 reviews
Read
November 9, 2016
There is a good chapter about "feature detection" and "feature inference"
Displaying 1 - 29 of 29 reviews

Can't find what you're looking for?

Get help and learn more about the design.