Skip to content

Instantly share code, notes, and snippets.

@roachhd
Last active August 29, 2015 14:08
Show Gist options
  • Save roachhd/309f9af1b70ed9f5de25 to your computer and use it in GitHub Desktop.
Save roachhd/309f9af1b70ed9f5de25 to your computer and use it in GitHub Desktop.
Quick Reference: Code comments of all varieties

How to Write Comments

######HTML Writing comments in HTML, XHTML, and XML. Simply surround the text you want commented out with

<!-- YOUR TEXT HERE -->

If you want to stop your JavaScript from executing when placed in a HTML_file add // before the end -->

<!--  YOUR SCRIPT HERE //-->

######CSS In CSS, it's a little different, using C code style comments.

 /* YOUR TEXT HERE */

Same goes for multi-line comments.

/* This is
a multi-line
comment */

######JavaScript Single Line Comments in a Javascript file start with //

Any text between // and the end of a line, will be will not be executed

The example below is a single line comment in front of each line, to explain the code.

// Change heading:
document.getElementById("myH").innerHTML = "My First Page";
// Change paragraph:
document.getElementById("myP").innerHTML = "My first paragraph.";

Javascript comments can also be placed at the end of the line of code.

var x = 7;      // Declare x, give it the value of 7

Using comments to prevent execution of code can be awesome for testing.

Adding // in front of a code line changes the code lines from an executable line to a comment.

The below example uses // to prevent execution of a single line of code.

var x = 5;      // Declare x, give it the value of 5

You can also stop multiple lines from exciting by using /* at the start and */ at the end.

/*
document.getElementById("myH").innerHTML = "My First Page";
document.getElementById("myP").innerHTML = "My first paragraph.";
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment