JavaScript basic syntax 03 - JS comments, terminators

Hello everyone, I am Lei Gong!
Today we continue to learn the basic syntax knowledge of JavaScript, comments and terminators. The following are study notes.

1. JavaScript comments

What do JavaScript comments do?
JavaScript comments can improve the readability of the code and help novices like me understand the code better.
JavaScript comments can also be used to prevent code execution when testing alternative code. It is often used when debugging.

1. Single line comment
1.1. Symbol: //
1.2. Function: //The entire line of code on the right will be ignored
1.3. Shortcut key: CTRL+/

Example:

    <script>
            //这就是单行注释
            //一次注释一整行
            //可以重复注释
    </script>

2. Multi-line comments (block comments)
2.1. Symbols: /* /; starts with / and ends with /.
2.2. Function:
All content between / and */ will be ignored.
2.3. Shortcut key: SHIFT+ALT+A

Example:

    <script>
            /*这就是多行注释*/

            /*
               一般都是这样写
                其间可以任意回车任意换行
                多少行(hang)都行(xing)
            */
    </script>

3. Benefits of writing comments.
Developing a good habit of writing comments not only makes it easier to quickly understand the code and maintain the code during secondary reading; it also facilitates colleagues or others to understand and maintain the code if the project changes hands.

Insert image description here

2. JavaScript terminator

1. Function: Use; to represent the end of a sentence (English;).
2. In practice: In the actual development process, the terminator can be written or not, and the browser can automatically determine the end position of the statement.
3. In order to unify the style, the ending symbol must be written in every sentence or not written at all. If there are development specifications, you can follow the specifications.

Examples of terminators:

    <script>
        alert('hello');
        alert('欢迎关注雷工笔记');
    </script>

Example without terminator:

    <script>
        alert('hello')
        alert('欢迎关注雷工笔记'</script>

3. Postscript

The above is the basic knowledge about JavaScript basic syntax comments and terminators. Please correct me if there is any inappropriateness.
Always believe that good things are about to happen. ——XiaoMi

Guess you like

Origin blog.csdn.net/u013097500/article/details/132622534