JavaScript beginners: 004-JS annotation Writing Method and basic operators, 004js

Source: Internet
Author: User
Tags comment tag html comment

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.