JavaScript DOM Programming Art (2nd edition)---P9

Source: Internet
Author: User

2.1 How to introduce JS file

(1) Introduction of external JS

Example:

(2) on the current page

Example:

This part of the content can be placed anywhere on the page. But it is usually placed at the bottom of the page. This makes it easy for the page to load and then execute the JS file.

2.2 Syntax

Grammar: The rules of language structure.

Statement: The instruction is the basic unit that makes up any script.

Recommendation: Add a semicolon at the end of each statement.

Note: single-line Comment "//", multiline Comment "/*....*/" (HTML-style comments are not recommended in JS code)

Variable

Variable declaration:

< Script >    var Mood;//mood, "Mood"     var Age ; </ Script >

Other ways (Assignment method):

<Script>    //First Kind    varMood="Happy"; var Age= -; //The second Kind    varmood2="Sad", Age2= at; //Third Kind    varMood3,age3; Mood3="Cool"; Age3= -; //where the second most efficient, a statement is equivalent to the sum of the third method</Script>
Some naming conventions:

In the JavaScript language, the names of variables and other grammatical elements are case-sensitive.

JavaScript syntax does not allow a variable name to contain spaces or punctuation (the dollar sign "$" exception)

JavaScript variable names are allowed to contain letters, numbers, dollar signs, and underscores (but the first character is not allowed to be a number)

Hump format naming:

Remove Middle white space (underline), followed by each new word start with uppercase letters

< Script >    var  ="happy"; </ Script >

Usually the hump format is the preferred format for function name, method name, and object property name naming

Simple "Happy" is a literal (literal) in the JavaScript language, which is data that can be written directly in JavaScript code.

"Var" is a keyword, mymood is a variable name.

Cond...

JavaScript DOM Programming Art (2nd edition)---P9

Related Article

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.