JavaScript comments

It's useful to make notes to yourself and to others so that when they look at your code in a few years time they can quickly understand what is doing what. To put comments into JavaScript use either:

// this is a single line comment about the following code
alert('Hi');
/* that last line was pretty pointless and so is the next one.  This is a multi-line 
comment.  Both types can be used to "comment out" lines of code temporarily so 
that they are ignored by the browser (maybe while you try to fix them). */
alert('Bye');
        

Get into the habit now of commenting all of your code. Explain what it does almost line by line but certainly each block. Commenting out code temporarily for troubleshooting is also useful.

submit to reddit Delicious Tweet