First knowledge of JavaScript

Source: Internet
Author: User

Introduction to JavaScript

JavaScript is a literal-translation scripting language, which is a dynamic type, a weak type, a prototype-based language, and a built-in support type. Its interpreter, known as the JavaScript engine, is widely used as a scripting language for the client, and is used in HTML (an application under the standard Universal Markup Language) to add dynamic functionality to an HTML Web page. Because JavaScript is compatible with the ECMA standard, it is also known as ECMAScript.

  ECMAScript, describes the syntax and the basic object of the language's JavaScript composition .

The Document Object Model (DOM), which describes the methods and interfaces for working with Web page content.

A Browser object model (BOM) that describes the methods and interfaces that interact with the browser.

JavaScript Basic Features

1, is an explanatory scripting language (code is not precompiled)

2, mainly used to add interactive behavior to HTML (an application under standard Universal Markup Language) page

3, can be directly embedded HTML page, but written as a separate JS file conducive to the separation of structure and behavior

4, cross-platform features, under the support of most browsers, can be run on a variety of platforms (such as Windows, Linux, Mac, Android, iOS, etc.)

JavaScript uses

1. Scripts in HTML must be between <script> and </script> tags. The script can be placed in the <body> and <!DOCTYPE HTML><HTML> <Head> <MetaCharSet= "UTF-8"> <title>Document</title> <Script> //put JavaScript code here .Alert ("This is a test"); </Script> </Head> <Body> <Script> //put JavaScript code here .Alert ("This is a test"); </Script> </Body></HTML>

2, JavaScript script can also be placed in the HTML external extension (. js) file (external script can not contain <script> tags), so as to better achieve the separation of behavior and structure.

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "UTF-8">        <title>Document</title>    </Head>    <Body><!--introduce external JS files--<Scriptsrc= "Js/my.js"></Script>    </Body></HTML>

3. JavaScript annotations

  1  <script> 2  //  single line comment   3  // document.createelement (" myelement ");   4  /*   5   multiline comment   6   Document.createelement ("myelement");   7   document.createelement ("myelement");   8   document.createelement ("myelement");   9  */ 10  </script> 

4. JavaScript statements and code blocks

Each JavaScript statement requires a semicolon (;) to end, and the procedure for omitting semicolons does not make an error, but a semicolon is generally required, with the following advantages:

1, improve code performance, if there is no semicolon parser need to analyze and determine where to insert a semicolon.

2, improve the correct rate of code, such as to write multiple lines of code on one line, there is no semicolon error is very likely.

JavaScript multiple statements are grouped together and placed in acurly braces ({})The statement block is formed within the
//JavaScript Statementsvarx = 1;varx = 1; vary = 2;//writing multiple statements on one line is not recommended//JavaScript statement blocks, statement blocks can be nestedif(2 > 1) {x= 1; Y= 2; Z= 3; if(X <y) {z= 4; }    if(X >y) {z= 5; }}

5. JavaScript case

JavaScript isstrictly case-sensitive, if the case is wrong, the program will error or not run properly. In a JavaScript program: JavaScript and JavaScript are completely different.

First knowledge of 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.