JavaScript comments and whitespace

JavaScript comments and whitespace

documenting the script

·

1 min read

Table of contents

Two documentation terms and code concepts:

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

However, JavaScript will let us to do things like this:

let x=1

or this:

let x    =               1

but why? Let's just stick to this kind of convention:

let x = 1