Keep It Consistent

The way you format your code is up to you (or the team you are working with). As you saw in the three code examples just now, the way you format your code doesn’t affect the way your code runs (see “Python Style” for a caveat). You should decide how you are going to format your code and then consistently follow the conventions you have chosen. Staying consistent in your formatting will help make your code more readable (see Listing 9.2 for an anti-example), and it can also help you avoid bugs. In all the code examples in this book, I have used single quotes for strings, but I could have used double quotes. JavaScript understands both. However, if you start a string with a double quote, you must end it with a double quote, and ...

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.