Get the App
SLTechnology News&Howtos  ›  Development  › 

How to improve the readability of code in JavaScript

Shulou Source: shulou.com Published: 2022-06-01 13:13:45 10月05日 Update

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!

Tags: Comments code readability multiline article face-to-face explanation output example content title paragraph in line not much home page representative most beginning more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info NVidia Shulou Technology Docker Shulou Information