Skip to Content

Advertisement

You (Level 0)
0% Complete
Last Badge Earned
None

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

I've attached my favorite JavaScript and jQuery book. I would encourage you to read it as well.

Your code will execute in this window.



Let's explore some more tutorials or topics!

Next Tutorial Previous Tutorial

Advertisement

If you enjoyed this resource, support me by sharing this page with others.

Comment on

Show Comments
  • User

    orasare July 7, 2014, 1:29 a.m.

    this article is very good



Advertisement