Javascript comments on same line as code: yes or n

2019-09-22 09:03发布

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; //Amount speed is divided by each frame

Is that kosher, putting the comments on the same line as the code? Firefox and Chrome don't seem to be having any problems with it, but does that have the potential to break certain browsers?

3条回答
孤傲高冷的网名
2楼-- · 2019-09-22 10:00

... 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.

查看更多
Melony?
3楼-- · 2019-09-22 10:01

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.

查看更多
小情绪 Triste *
4楼-- · 2019-09-22 10:02

Your fine, the commented out code begins after the backslashes and ends at the end of the line.

查看更多
登录 后发表回答