JavaScript Tutorial Series - Comments

Comments are used to make notes in source code about what a piece of code does or to not include executable lines of code when the application is run. Comments are not rendered on the page when the containing JavaScript file is loaded.
Comments are created in JavaScript by adding 2 forward slashes, //, in front of the line of code to exclude. Example:

// This is a comment.

To comment multiple lines of code, a forward slash and asterisk, /* starts a block of commented out code. An asterisk and forward slash, */, will end the block of commented out code. Example:

/* This is a
   multi line comment.*/

Implementation:

Inside the javascript_tutorial.js file created in the JavaScript set up tutorial, add the following:


// JavaScript Tutorial

/*
* This file will add JavaScript
* to a website.
*/


Save it and open the index.html in a web browser. Notice the comments in the javascript_tutorial.js file are not displayed on the web page.

The JavaScript tutorial series starts with this post.


(paid links)

Comments