JavaScript comments and whitespace
// updated 2025-05-02 06:30
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:
1// this is a comment in JavaScript
2
3/*
4
5this is also a comment in JavaScript
6
7when we want to write something
8
9longer than one line
10
11*/
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.:
1let x = 1
We cannot write the following, for example, and expect the code to behave in the same fashion as the above:
1letx=1
JavaScript allows us to do things like:
1let x=1
However, for good practice we will just use this sort of spacing:
1let x = 1
We could still do more than one space like this
1let x = 1
No matter how we space it, we should choose a convention and stick to it all throughout a script!