Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to improve the readability of code in JavaScript

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to improve the readability of the code in JavaScript, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

JavaScript comment

JavaScript comments can be used to improve the readability of your code.

JavaScript does not perform comments.

We can add comments to interpret the JavaScript or improve the readability of the code.

JavaScript multiline comment

One-line comments begin with / /. It is common to use single-line comments to interpret code:

/ / output title: document.getElementById ("myH1") [xss_clean] = "Welcome to my Homepage"; / / output paragraph: document.getElementById ("myP") [xss_clean] = "This is my first paragraph."

Comments are not executed.

JavaScript multiline comment

Multiline comments begin with / * and end with * /. Multiline comments are usually used to interpret the code:

/ * the following code outputs a title and a paragraph and will represent the beginning of the home page * / document.getElementById ("myH1") [xss_clean] = "Welcome to my Homepage"; document.getElementById ("myP") [xss_clean] = "This is my first paragraph."

Use comments to prevent execution

In the following example, comments are used to prevent the execution of one of the lines of code (which can be used for debugging):

/ / document.getElementById ("myH1") [xss_clean] = "Welcome to my Homepage"; document.getElementById ("myP") [xss_clean] = "This is my first paragraph."

In the following example, comments are used to prevent the execution of code blocks (which can be used for debugging):

/ * document.getElementById ("myH1") [xss_clean] = "Welcome to my Homepage"; document.getElementById ("myP") [xss_clean] = "This is my first paragraph."; * /

Use comments at the end of the line

Var xdeclare 5; / / declare x and assign 5 to it var yearly xroom2; / / declare y and assign it document.getElementById ("myP") [xss_clean] = y / / write the value of y to myP

Comments at the end of the line are not executed.

These are all the contents of the article "how to improve the readability of code in JavaScript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report