Home  >  Article  >  Backend Development  >  Should single-line comments be placed at the end of the line or above the code?

Should single-line comments be placed at the end of the line or above the code?

WBOY
WBOYOriginal
2016-12-01 00:00:401588browse

If it is necessary to add a single-line comment, do developers generally put the single-line comment at the end of the code line, or should it be placed on its own line above the code? Or is it a specific situation and detailed analysis? Is it a personal habit or does it have your reasons. I hope everyone can discuss it so that I can learn more.

  • End of line

<code>var var1 = 5; // 声明并初始化变量,值为5</code>
  • Above

<code>// 声明并初始化变量,值为5
var var1 = 5; </code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn