JavaScript comments and whitespace
Here we will outline two handy concepts regarding documentation in JavaScript: comments and whitespace!
Comments
Comments allow us to place notes inside the code, without affecting how the program runs:
// this is a comment in JavaScript
/*
this is also a comment in JavaScript
when we want to write something
longer than one line
*/
However, we do hope to write our JavaScript clearly enough so that we can avoid excessive commenting!
Whitespace
To a certain extent, whitespace does not affect the running of JavaScript past the first space, e.g.:
let x = 1
We cannot write the following, for example, and expect the code to behave in the same fashion as the above:
letx=1
JavaScript allows us to do things like:
let x=1
However, for good practice we will just use this sort of spacing:
let x = 1
We could still do more than one space like this
let x = 1
No matter how we space it, we should choose a convention and stick to it all throughout a script!