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 trialMICHAEL P
5,191 PointsIn order to have proper syntax in JavaScript, when commenting do you always begin line with // ?
In order to have proper syntax in JavaScript, when commenting do you always begin line with // ?
Like, I know that // is not the only way to comment in JavaScript, since you can also have / /
but when you type the // for commenting in JavaScript, do you need to always include // at the beginning of the line?
It seems that JavaScript is slightly less strict as far as syntax. That is why I was wondering. Thanks
4 Answers
Chris Adamson
132,143 PointsIt doesn't have to strictly be at the beginning of the line, you could have it come after functional code as well:
i = 1; // comment
/ / wouldn't be a comment in Javascript, the two backslashes have to be together to start a comment.
Chris Adamson
132,143 PointsIf your troubleshooting your code, using the
/*
*/
style of comments can be convenient to comment out large sections of code to find bugs.
MICHAEL P
5,191 PointsThank you
Erik c
Front End Web Development Techdegree Student 3,560 PointsAnother way you can comment is by adding /*
at the beginning and close it off with */
This is an option if you're writing a longer comment.
/*
Everything inside will be considered
a comment and you can have as many lines needed
and then you close it off with an asterisk and forward slash
*/