Computer Consultant

Computer Consultant, Network Security Consulting, Computer Consultants

     Computer Consultant | Network Security Consulting


Recent posts




Blogger Template

PHP Basic

PHP Reference

PHP Advance

JavaScript Basic



Custom Search





JavaScript Comments

JavaScript Comments


Comments can be added to explain the JavaScript, or to make it more readable.


Single line comments start with //.


This example uses single line comments to explain the code:





<script type="text/javascript">
// This will write a header:
document.write("<h1>This is a header</h1>");
// This will write two paragraphs:
document.write("<p>This is a paragraph</p>");
document.write("<p>This is another paragraph</p>");

</script>


Try it yourself.





JavaScript Multi-Line Comments


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


This example uses a multi line comment to explain the code:





<script type="text/javascript">

/*
The code below will write
one header and two paragraphs
*/
document.write("<h1>This is a header</h1>");
document.write("<p>This is a paragraph</p>");
document.write("<p>This is another paragraph</p>");
</script>



Try it yourself.





Using Comments to Prevent Execution



In this example the comment is used to prevent the execution of a single code line:





<script type="text/javascript">
document.write("<h1>This is a header</h1>");
document.write("<p>This is a paragraph</p>");
//document.write("<p>This is another paragraph</p>");

</script>


Try it yourself.



In this example the comments is used to prevent the execution of multiple code lines:





<script type="text/javascript">
/*
document.write("<h1>This is a header</h1>");
document.write("<p>This is a paragraph</p>");
document.write("<p>This is another paragraph</p>");
*/

</script>


Try it yourself.





Using Comments at the End of a Line



In this example the comment is placed at the end of a line:





<script type="text/javascript">

document.write("Hello"); // This will write "Hello"
document.write("Dolly"); // This will write "Dolly"
</script>







Gayabo

posted by Computer @ 10:42,

0 Comments:

Post a Comment

<< Home


Blogger