How to comment in code and what are its benefits

清浅
Release: 2018-12-11 09:23:46
Original
8885 people have browsed it

In the code, you can use the Ctrl / shortcut key to comment the code, which helps us understand the code, speed up the development process and maintain code consistency

When we One thing you usually learn when learning HTML or CSS is how to write comments in your code. However, many developers still don't use annotations to their advantage. Today we will introduce how to use comments extensively in HTML and CSS to improve our workflow.

【Recommended course: HTML Tutorial

How to comment in code and what are its benefits

##Importance of comments:

If we are doing an independent project, or are the only developer to review the code we have written, then we can Write code according to your own ideas. But if you are working with others, if the code does not have any comments, it will be difficult for others to understand and understand the meaning of the code. This will increase the burden of cooperation on the developers, but having comments will greatly reduce the burden.

Benefits of learning to comment:

(1) Helps maintain consistency

(2) Helps understand

(3) Help with patches or quick fixes

(4) Help speed up the development process

(5) Help improve collaboration efficiency

Note :

Be careful not to write too long when commenting on the code. This will increase the redundancy of the code and avoid spending a lot of time writing unimportant comments.

How to comment in the code

(1) In the HTML code:

<body>
<!--HTML代码-->
<div>hello world!</div>
</body>
Copy after login

To comment the code in HTML, just add < !--Comment content--> That’s it, we can use the shortcut key Ctrl / to complete

(2) In the CSS code:

<style>
div{
width:100px;
height:30px;
border:1px solid #ccc;
/*设置字体垂直居中*/
text-align: center;
line-height: 30px;
}
</style>
Copy after login

The comment in CSS is /**/ , the shortcut key is Ctrl /

(3)

<script type="text/javascript">
		// 点击div时改变其背景颜色
		var div=document.getElementsByTagName("div")[0];
		div.onclick=function(){
			div.style.backgroundColor="pink"
		}
	</script>
Copy after login

in JavaScript code, the comment in JavaScript is //, the shortcut key is Ctrl /

Rendering

Before clicking:

How to comment in code and what are its benefits

After clicking:

How to comment in code and what are its benefits


Summary: Above That’s all the content of this article, I hope it will be helpful to everyone.

The above is the detailed content of How to comment in code and what are its benefits. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template