Previous Example-|-Next Example-|-Return to Chapter Listing


Example 3.4:
Comments Lines


1. The following is a script with no HTML comment tags--if you use a non-JavaScript-compatible browser you'll be able to see the script.


This is the script we used:

<script language="JAVASCRIPT"> document.write("This document last modified on: ") document.write(document.lastModified) </script>


2. The following is the same script, but containing the comment tags--use a non-JavaScript-compatible browser and you won't see the script this time.


This is the script we used:

<script language="JAVASCRIPT"> <!-- document.write("This document last modified on: ") document.write(document.lastModified) //--> </script>


3. The following is the same script, this time with two different JavaScript comment lines; a single-line comment before the script and a multi-line comment after. You can see it all with a non-JavaScript-compatible browser, because we haven't used the HTML comment tags.


<script language="JAVASCRIPT"> // This is a single-line comment--no need to end the comment with anything. document.write("This document last modified on: ") document.write(document.lastModified) /* Here is a multi-line comment; you don't need to place anything at the beginning of the lines in the middle, but you do need to end the comment by putting the asterisk and a backslash at the end of the last line */ </script>

4. Finally, the other comment methods:


These are the scripts we used:

<script language="JAVASCRIPT"> <!-- function AlertBox(){ //I’ve defined a function here alert("This is the alert box" ) //the function runs alert } document.write("This document last modified on: ") //now I’m writing text document.write(document.lastModified) //grabbing the document’s //modified date //--> </script> <script language="JAVASCRIPT"> /* This is the beginning of a multi-line comment * this is the second line * this is the third line * This is the last line of the multi-line comment */ </script>


Previous Example-|-Next Example-|-Return to Chapter Listing