JS Syntax Basics

Source: Internet
Author: User

1. Introduction method

<script type= "Text/javascript" > Specific code </script>

<script type= "Text/javascript" src= "Apple.js" ></script>

2. Case-sensitive

JavaScript language is strictly case-sensitive name name

3. How to Annotate

Comment Line

/*

Comment Multiple lines

*/

4. The end of the disposition number can be omitted (multiple expressions written in one line cannot be omitted)

var name= "Tom";

var age = 23;

5. Variable naming rules

Name composition: Letters, numbers, underscores, $

The first character of the start cannot be a number.

var $ = "China"; Yes, the jquery framework

var 9 = "Hello"; No

6. Global variables and local variables

① define "global variables" in JS and define them directly at any corner of the system (without using the var keyword)

② special cases, variables defined by Var outside the function are also "global"

Variables defined by var outside of nested functions in the ③ function can be used relative to this function

7. Connection Symbol +

  When two parameters are numeric, do arithmetic operations; When two parameters one or two are string types, do the link operation

8. Break and Continue

Jump out of a loop and use it directly, if you need to jump out of multiple loops, use the following methods:

Waibian: For        (var i=0; i<10; i++) {            document.write (i+ "<br/>");            for (var j=100; j>=90; j--) {                //j==95 jumps outside the loop break                //if (j==95) {                    //break 2;    Do not use the number 2 (this usage is PHP's syntax rule)                //Break    Waibian;                }                                //j==95 jumps out of the "This" loop (let the outer for loop go directly to the next)                if (j==95) {                    continue Waibian;                }                document.write (j+ "<br/>");            }        }

9.switch

A switch condition can be a value, an expression, and a case can be followed by a constant, a variable, an expression

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.