JavaScript and javascript

Source: Internet
Author: User

JavaScript and javascript
 JavaScript syntax

 

I. Introduction

 

JavaScript is an interpreted programming language that does not require a compiler, but only an interpreter. The Web browser is responsible for completing the interpretation and execution.

Compiling JavaScript requires no special tools (some are more powerful, such as jetbrainswebstorm and Sublime Text ).

Use JavaScript on the page: 1. Add <script> // body... </Script>. 2. Put all JavaScript content in a file named ***. use <script src = '*** in js files and pages '***. js '> </script>.

 

Ii. Syntax

 

1. Statements

 

Scripts written in JavaScript are composed of a series of commands called statements ). Multiple statements can be separated by semicolons (;) in one row. You do not need to use semicolons or separate one line for each statement. We recommend that you put a statement in one row and end it with a semicolon. Good Programming habits are basic qualities.

 

2. Notes

 

The document information used to help understand program execution statements is ignored by the interpreter. Common annotation methods:

// Single-line comments/* block comments * // ** document-type comments, which are common in Java classes */<! -HTML-style comments and single-line locks. -->

3. Variables

 

Variable: something that changes.

Variable: Declaration (declare) and assignment (assignment ). JavaScript is a weakly typed language, and its variable definition uses var as the prefix regardless of the type of the variable. For example, var name = "alien", age = 25;

Variable scope:

  1. Global variable: acts on the entire script and is defined externally in any function.

  2. Local variable: applies only to the function that declares the local variable.

 

4. Data Type

 

There are six Data Types in JavaScript: five basic types and one reference type. The details are as follows:

Basic types: boolean, number, string, null, and undefined.

Reference Type: Object. The Object is divided into user-defined objects. Native object (such as Date, Math, and other built-in objects ). Array and function all belong to the Object type in JavaScript.

It can also be divided into the following parts:

Primary data type: String, Number, Booelan

Data Types: Object and Array

Specific data types: Null and undefined

When the data type is combined with the following operators, and how to determine the type of a variable, there will be some confusing points, which will be recorded separately in the next note. Here is only a conceptual record.

 

Iii. Operations

 

Arithmetic Operator (arithmeticoperation): +-*/+ =-=

Auto-increment and auto-increment (before and after the sub-operation): ++ --

Comparison operator (comparisonoperators): ><>==! ====

Logical operators (logicaloperators): || &&!

 

Iv. Condition statements

 

if (condition) {   statements; }else if (condition) {   statements; }else{   statements; }

 

V. Cyclic statements

 

1. while Loop

 

//while circulationwhile (condition) {   statements;}

2. do... While Loop

 

do{   statements;}while(condition);

3. for Loop

 

for (initial condition; test condition; alter condition) {   statements;}

Vi. Functions

 

Encapsulate the same code that needs to be used multiple times into a function. A function is a group of statements that can be called at any time in the code.

function methodName ( parameter ... ) {   //body statements;}

7. Object

 

1. attributes and methods of the object:

 

Duplicate objects are of this type because of their importance. An object is a self-contained data set. data contained in an object can be accessed in two forms: property and method ):

Property is a variable belonging to an Object: Object. property

Function that can only be called by a specific Object in a method: Object. method ()

2. Object Classification

 

  1. Native object: A series of predefined objects provided by JavaScript. For example, arrays are one of them, and commonly used Math and Date. These objects can be used directly.

  2. Host object: a predefined object provided by the browser. Such as Form, Image, Element, and document objects.

  3. User-defined object: user-defined object, definition method: functionPerson () {// body... }.

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.