Javascript Comments On Same Line As Code: Yes Or No?
So here's some code I've written in Javascript: var panRate = 120; //Max speed of the camera var panAccelerate = 0.01; //Amount speed increases each frame var panDecelerate = 1.05;
Solution 1:
Javascript has 2 types of comments, and both work in all browsers.
// comment
denotes an "inline" comment. Any characters on that line after the//
are a comment./* comment */
are "block" comments. Any characters withing the/*
and*/
are a comment, and can span multiple lines.
Both are valid in all javascript implementations, universally.
Style is the only real concern here. And that is a far more subjective question.
Solution 2:
... but does that have the potential to break certain browsers?
No, not any browser that's remotely compliant with the ECMAScript specification. No browser I've ever seen has any problem with them. This is incredibly basic, if a browser has an issue with this, it will have bigger issues for you to worry about. So don't worry about this.
Solution 3:
Your fine, the commented out code begins after the backslashes and ends at the end of the line.
Post a Comment for "Javascript Comments On Same Line As Code: Yes Or No?"