Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Document Your Code With Comments

// Comments vs /* */ Comments

I've seen a few JavaScript source files where the developer chose to use multiple single line comments (//) in place of a multiple line comment (/* */). Is using single line comments in this matter something that is frowned upon in production code? Additionally, from a does it make any difference to how a program interprets those comments?

1 Answer

Steven Parker
Steven Parker
231,269 Points

A single line comment is in effect from where it starts ("//") to the end of the current line. A multi-line comment is in effect from where it starts ("/*") until it explicitly ends ("*/") no matter how many lines are involved.

I'm not aware of any general "best practice" rules that prefer one type over the other, but some organizations may provide their own code formatting specifications that they require developers to adhere to. In the absence of such rules I would expect it to be purely "programmer's choice".