Document to Teach

I have learned a lot about programming by reading other people’s code, especially other people’s comments. When you are using an interesting technique, you have an opportunity to teach your fellow developers about that technique and show why it’s great. By taking the time to document to teach, you also learn more about the technique yourself. Listing 10.14 shows one of my favorite techniques for looping through an array. I learned about this technique from the JSHint documentation.

Listing 10.14 Assignments in the Conditional of a for Loop

var letters = ['a', 'b', 'c'];var letter, i;// Instead of using the length of the array, use the for loop's conditional to// make assignments. When there are ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.