Home  >  Article  >  Web Front-end  >  Several methods of commenting code in javascript (graphic tutorial)

Several methods of commenting code in javascript (graphic tutorial)

亚连
亚连Original
2018-05-19 13:41:242923browse

In order to make the program/code easier to read, basically every programming language has the function of commenting, and JavaScript is no exception. There are many forms of JavaScript comment code. This article introduces two methods of commenting code in JavaScript. Friends who need it can refer to

There are generally two methods for javascript comment code:

Single-line comments

Multi-line comments

javascript single-line comments

Single-line comments start with "//" and end at the end of the new line. The following is an example of a javascript single-line comment:



javascript单行注释


javascript multi-line comment

Multi-line comments start with /*, End with */. The following example uses multi-line comments to explain the code:



javascript多行注释


How to solve the problem that the browser does not support javascript

App Comment symbols verify whether the browser supports JavaScript script function.

If the user is not sure whether the browser supports JavaScript script, then the comment symbols provided by HTML can be used for verification. HTML comment symbols start with "f98a2fb10194037464bfe9c316f9d8ac". If you write a JavaScript script within this comment symbol, browsers that do not support JavaScript will treat the written JavaScript script as a comment.

Use JavaScript script to output a string in the page. Write the JavaScript script in the HTML comment. If the browser supports JavaScript, this string will be output. If not, this string will not be output. The code is as follows:



Hide scripts using comments.


Page content here...

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Basics of the prototype concept of Object objects in JS (detailed content, clear at a glance)

12 entries How to produce high-quality JS code (teaching you to write high-quality code)

Detailed introduction to the difference between Map and ForEach in JS

The above is the detailed content of Several methods of commenting code in javascript (graphic tutorial). For more information, please follow other related articles on the PHP Chinese website!

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