JavaScript Learning Summary-Basic syntax-(i)

Source: Internet
Author: User

1.1.javascript Introduction (citing Baidu Encyclopedia explained)

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. In 1995, the Brendan Eich of Netscape Company was first designed and implemented in Netscape Navigator's browser. Because Netscape is working with Sun, Netscape Management wants it to look like Java, so it's named JavaScript. But in fact its grammatical style is closer to self and scheme. [1] In order to gain technical advantage, Microsoft launched the Jscript,cenvi launch Scriptease, and JavaScript can also be run on the browser. For uniform specifications, JavaScript is also known as ECMAScript because it is compatible with the ECMA standard. 1.2.javascrip features

-Security (does not allow direct access to the local hard disk), what it can do is the dynamic interaction of information.

-Cross-platform. (As long as the browser can interpret JS can be executed, and platform-independent.) )

The difference between 1.3.javascript and Java

-js is the product of Netscape company, and Java is the product of sun company.

-js is Object-based and Java is object-oriented.

-js can be executed with just an explanation, and Java needs to be compiled into a bytecode file before execution.

-js is a weak type, and Java is strongly typed.

1.4.javascript Learning Content

-javascript Grammar Basics

-Use JS to manipulate Web pages (DOM)

-Use JS to manipulate the browser (BOM)

2.JAVASCRIPT Foundation

2.1. Basic syntax

2.1.1. Introduction and introduction Location

The primary way to insert JavaScript into an HTML page is to use the <script element >.

There are two ways to use the <script> element: embed JavaScript code directly in the HTML page and include external JavaScript files.

-js code is stored in the label to <script> </script> in.

Internal

<script> the location of the label

The location of the <script> label should be placed in the

Attention:

1, the page can have multiple <script> tags

2. <script> tags executed sequentially

3, <script> tags can appear in any page location

4, <script> label must write </script> close, but not <script/> so close. Otherwise there is no error message, but the result is not running.

External

-Introduce a JS file using the SRC attribute of the script tag. (Convenient post-maintenance, extension)

Example: <script src= "Test.js" type= "Text/javascript" ></script>

Note: The type attribute must be added to the script tag in the specification

2.1.2. Case sensitivity

Like Java, variables, function names, operators, and everything else are case-sensitive.

Like what:

The variable test is different from the variable test.

2.1.3. Notes

Java:////* */** * *

HTML: <!---->

CSS:/* * *

Javascript:

ECMAScript comments and Java language annotations are the same

ECMAScript The annotation syntax for these languages is borrowed.

There are two types of annotations:

Single-line comments start with a double slash (//)

Multiline comments start with a single slash and asterisk (/*), ending with an asterisk and a single slash (*/)

2.2. Common functions

Window.alert () or write as alert (): Displays a prompt box to display the contents.

Window.document.write (): writes content at the current location of the Web page.

2.3. Variables

Variables are weakly typed.

Unlike Java, a variable in ECMAScript has no specific type, and it can be initialized to any value by using the var operator only when defining a variable.

Therefore, you can change the type of data that the variable is stored at any time (try to avoid doing so).

Example

var color = "Red";

var num = 25;

var visible = true;

The variables in ECMAScript are defined with the var operator (abbreviated by variable) plus the variable name. For example:

var test = "HI";

In this example, the variable test is declared and its value is initialized to "HI" (The string).

Each variable is just a placeholder for holding the value. Use the var operator when defining a variable (var is the keyword) followed by the variable name

VAR message;

This line of code defines a variable named message that can be used to hold any value, or to initialize the variable directly.

var message = "HI";

The variable in ECMAScript has no specific type, and it can be initialized to any value by using the var operator only when defining the variable.

<script type= "Text/javascript" >        //define variable        var color = "Red";        var num =;        var visible = true;      </script>

  

At the same time, you can change the type of data stored in the variable at any time (try to avoid doing so).

<script type= "Text/javascript" >         //define variable         var message = "Hello";        message = +;        alert (message);      </script>

In this case, the variable message starts with a string value of "HI" and is replaced by a value of 100. This is valid in ECMAScript, but is not recommended for this use.

Usage Details:

1, the var keyword in the definition of variables can be omitted to write

2, the variable name can be repeated, the following will overwrite the previous variable

3. The type of the variable depends on the type of the value

A statement defines multiple variables.

The middle is separated by a bean number, can be initialized or not initialized.

<script type= "Text/javascript" >        var name = "Jack", age        = +,        gender = "Male";</script>

  

JavaScript code block and its code block variable scope

<script type= "Text/javascript" >        //code block (Java) encapsulates code for the scope of the isolated variable        {            var a = +;            document.write (A + "</br>");         } {            document.write (A + "</br>");           JavaScript does not isolate variable scopes        }       </script>

JavaScript Learning Summary-Basic syntax-(i)

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.