Commenting in JavaScript

You can comment code in Javascript in two different ways. A typical XML comment begins with the following code:

/*

A typical XML comment ends with the following code:

*/

For example:

/* This is a comment */

You can also add a set of forward slashes (//) to comment an entire line of code. All code that occurs after these slashes on the line that contains the slashes is part of the comment. For example:

// This is a comment

Assume you must comment all of the following code:

var a = 0;
var b;
a = a + 1;
b = a;

The following syntax uses the slash and asterisk to comment all of the code:

/*
var a = 0;
var b;
a = a + 1;
b = a;
*/

The following syntax uses a set of forward slashes to comment all of the code:

// var a = 0;
// var b;
// a = a + 1;
// b = a;

In general, it is recommended that you use the slash and asterisk to comment multiple lines of code.