Black horse day19 JavaScript basic syntax

Source: Internet
Author: User

1.javaScript Introduction:

Development history:

* 1995 Netscape launched a new product: LiveScript. The Netscape company is very powerful, Microsoft has not launched the browser when the Netscape launched its own browser. But the livescript of its own is not in vogue.

* Netscape saw Java very much, so the United Sun Company launched a product: JavaScript ... So it really started to fire.

* Microsoft is very reluctant to see JavaScript in its own mind, and has launched its own JScript. So the world is messy ....

* Finally United Sun Company, Microsoft Corporation and European Association of Computer Control manufacturers: ECMAScript. is to make grammatical standards.

*javascript still has a problem, that is, version inconsistency, so programmers develop JavaScript to consider browser compatibility issues.

*javascript components:

(1) ECMAScript

* then developed into a standard: The syntax for developing languages, such as the naming conventions of variables

* Other scripting languages available on the market except javascript: ActionScript

* Almost every scripting language on the market has a standard: ECMAScript

*ECMA is not a proprietary JavaScript.

(2) BOM: Browser Object model

* Indicates that a series of objects exist in the browser

* Example: Window object

(3) DOM: Document Object Model

*javascript Script code: Let the content in the HTML page, render dynamic changes.

*javascript How does the script code parse the HTML page? Take advantage of DOM content

*javascript parsing an HTML page as a document.

ECMAScript Foundation

1. Variables

*var test= "Hello";

All variable declarations in JavaScript are in Var.

*ecmascript Another interesting thing is that you don't have to declare before you use a variable

var test1= "Hello";

test=test1+ "World";

alert (test);//Output Hellowrold

2. Original type

ECMAScript altogether there are 5 primitive types, namely undefined,null,boolean,number,string

You can compare types in Java such as Int-->integer is the original type

*undefined type

The undefined type has only one value, which is undefined. When the declared variable does not have an initialization value, it outputs undefined

var temp;

Alert (temp);//output "undefined" because temp is not initialized

*null type

The null type also has only one value of NULL. The value undefined is actually derived from null.

Alert (null==undefined)//Output True

*boolean type

It has a total of two values true and False

*number type

var inum=070;//defines 8-binary data

var inum=0x1f;//defines 16-binary data

var inum=10;//defines the decimal data

alert (iNum);//No matter what type of data iNum is, it will be converted to decimal data for output.

*string type

var scolor= "Blue";

3. Type conversion

Convert to String: ECMAScript defines many objects that have the ToString () method, and the ToString () method of the Boolean type just outputs True and false

The data of type number is very special:

Default mode and Base mode

var inum=10;

Alert (inum.tostring (2))//here 2 represents 2 binary, can also write 8,16

Converted into numbers:

var inum= "AAA";

Inum.parseint ();/output Nan, that is, only Var iNum must conform to some sort of rule

4.Object

JavaScript is also a weak language for facial objects

5. Relationship

= = = Three equals sign that the dish is true only if the type and value are the same

6.forin statements

var inum=[1,2,3];

for (var i in INum) {

alert (i);//I is subscript here

}

7.with statements

With (expression) {

Statement

}

var smessage= "HelloWorld";

With (smessage) {

Alert (toUpperCase ());

}//, this is the conversion of smessage to uppercase.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Black horse day19 JavaScript basic syntax

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.