concept whitespace in category angular

appears as: whitespace, whitespace
Getting MEAN with Mongo, Express, Angular, and Node.js 2ED

This is an excerpt from Manning's book Getting MEAN with Mongo, Express, Angular, and Node.js 2ED.

Don’t be afraid of whitespace

Adding a bit of whitespace between sets of braces can help readability and won’t cause any problems for JavaScript. Again, you’ve seen this approach in all the code snippets so far. You can also add or remove whitespace from between a lot of JavaScript operators. Take a look at the following code snippet, showing the same piece of code with and without extra whitespace.

Listing D.33. Examples of whitespace formatting
const firstname = 'Simon';                  #1
let surname;                                #1
if (firstname === 'Simon') {                #1
  surname = 'Holmes';                       #1
  console.log(`${firstname} ${surname}`);   #1
}                                           #1
const firstname='Simon';                    #2
let surname;                                #2
if(firstname==='Simon'){                    #2
  surname='Holmes';                         #2
  console.log(firstname+" "+surname);       #2
}                                           #2

As humans, we read by using whitespace as the delimiters for words, and the way we read code is no different. Yes, you can figure out the second part of the code snippet here, as many syntactic pointers act as delimiters, but it’s quicker and easier to read and understand the first part. JavaScript interpreters don’t notice the whitespace in these places, and if you’re concerned about increasing the file size for browser-based code, you can always minimize it before pushing it live.