0

I am new to JavaScript, and could use some clarification on the appropriate way to place JavaScript comments within an html file. I have spent time looking this up on the web, but I can only find instructions on how to comment in JavaScript not where to comment. I understand that comments within the script tags are fine (so long as they are not excessive). My question is whether or not it is ok to put JavaScript comments just before the script element. I want to know whether it is syntactically ok, and whether it is acceptable professional practice.

Example:

 // Added link to external js for TUT 1 Case 3
 <script type="text/javascript" src="../Data Files for Text/Tutorial.01/case3/functions.js"></script>

Is that acceptable, or should I be using html comments outside of the script since this is within an html file? Thanks for any help.

4
  • 4
    Try it and see what happens. Commented Feb 17, 2013 at 23:14
  • It's a pretty bad idea to use spaces in a path, you should avoid that Commented Feb 17, 2013 at 23:17
  • @ Blender I did, and didn't get any errors. However, the comments didn't "grey-out" like normal. Commented Feb 17, 2013 at 23:20
  • @romainberger Thanks for the tip. The path was actually auto generated by Adobe Dreamweaver, but thats good to know. Commented Feb 17, 2013 at 23:22

1 Answer 1

8
  • If you're using a markup language (e.g., HTML), use markup comments.
  • If you're in a <script> tag, use script comments.
  • If you're in a <style> tag, use style comments.

Examples:

<!--
  HTML comment
  (multi-line)
-->

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

/*
  script comment
  (multi-line)
*/
</script>

<style type="text/css">
/*
  style comment
  (multi-line)
*/
</style>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I guess that makes sense when you put it that way.
Also, note that the HTML comment and the /* */ style can be multi-line comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.