Tutorials

Learn web design and programming with our free video and text tutorials.

How To Add Comments to Javascript

You can add comments to your javascript code that are not executed or displayed on your web pages.

Single line comments start with //.

Multiple line comments start with /* and end with */.

The javascript code below shows you how to add single line and multiple line comments to javascript code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>WebDevelopmentTutorials.com</title>
</head>
<body>

<script type="text/javascript" language="javascript">

document.write("Hello World!");
// This is a single line comment
/*
This is a multiple line comment
This is a multiple line comment
*/

</script>

</body>
</html>

The javascript code above will display:

Hello World!