JavaScript beginners: 004-JS annotation Writing Method and basic operators, 004js
JS comments
Adding comments in JS is similar to writing C # code. There are two types: // and.
Single line comment
Use a double slash
For example,
<script type="text/javascript">// var number-1;// var index=2;</script>
Multi-line comment
Use/* content */
For example,
<script type="text/javascript">/* var number-1; var index=2; */</script>
Basic operators of JS
The basic operators in JavaScript are basically the same as those in common programming languages. The total number of operators is as follows:
Arithmetic Operator: +,-, *,/, %, ++ ,--
Assignment operator: =, + =,-=, * =,/=, % =
Comparison OPERATOR: = ,! =,>, <, >=, <=
Ternary operators:
? :
What is the role of adding html annotations in js?
Browsers that do not support JavaScript will display scripts as page content. To prevent this, we can use the following HTML comment Tag:
View plaincopy to clipboardprint?
<Html>
<Body>
<Script type = "text/javascript">
<! --
Document. write ("Hello World! ");
// -->
</Script>
</Body>
</Html>
<Html>
<Body>
<Script type = "text/javascript">
<! --
Document. write ("Hello World! ");
// -->
</Script>
</Body>
</Html>
The two front slashes at the end of the comment line are the annotation symbols of JavaScript, which will prevent the JavaScript compiler from compiling this line.
However, are there any browsers that do not support js?
How to Write javascript?
Why are you asking <! -- And --> well, this is a historical issue. A long time ago, not all browsers support scripts. browsers that do not support scripts do not process script tags, the content in the label is directly displayed on the page. Therefore, to prevent browsers that do not support scripts from directly displaying the code on the page, add the HTML comment tag at the beginning and end of the script tag <! -- And --> to prevent the script from being displayed. currently, few Browsers Do not support Javascript. Only some mobile browsers may not support it, but the script is not displayed. Therefore, this comment has lost its meaning today, you can stop writing.
HTML and JS annotations are different. JS uses/**/and // to annotate, so <! --> Does not affect the running of scripts in browsers that support JavaScript.