Comments

Before we get into commenting, I want to warn you about the slowly ending war of browser support for JavaScript. Back in the day, writing in JavaScript was a battle. You would have to write a ton of different statements for each different type of browser. Luckily, browsers are starting to get on the same page, and JavaScript is supported by all modern browsers. Update: Several years after writing this article, I must confess the entire world of JavaScript has changed. The assumption in the programming world is that a user will have JavaScript enabled if they intend to run any popular website. So, please code away in JavaScript.

JavaScript has a number of ways to comment

Example

<html>

<body>

<script type=”text/JavaScript”>

/*
document.write(“Everything here is commented.”);
document.write(“It is still commented out.”);
*/
document.write(“This is not commented.”);

</script>

</body>

</html>

The JavaScript comment above allows everything between the opening /* and the closing */ to be commented.

Example

<html>

<body>

<script type=”text/JavaScript”>

// document.write(“Everything on this line after the // is commented out.”);
document.write(“This is not in a comment.”);
document.write(“This is not commented out.”); //But everything on this line after the // is.

</script>

</body>

</html>

The // comment only comments out everything after it that is still on the same line. The first line of our code is all commented out because the // was at the beginning. However, on the third line, notice that the // is after the document.write method, and that the method is not in the comment.

References

0 thoughts on “Comments”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.