JavaScript

xiaoxiao2021-03-06  57

JavaScript has six data types. The main types have Number, String, Object, and Boolean types, the other two types are null and undefined.

String string type: The string is explained using a single quotation number or dual quotation. (Use single quotes to enter a string containing quotation marks.), "The Cow Jumped over the moon."

Numerical data type: JavaScript supports integers and floating point numbers. Integers can be positive, 0 or negative; the floating point number can contain a decimal point, or a "E" (large and lower writing can indicate "10 power" in scientific counting), or simultaneously contains both.

Boolean Type: Possible Boolean values ​​have True and False. This is two special values ​​and cannot be used as 1 and 0.

Undefined Data Type: A value for undefined means that the value has been previously assigned after the variable is created.

NULL Data Type: NULL value is not any value, what does not say.

Object Type: In addition to the various common types mentioned above, objects are also an important part of JavaScript, which will be described in detail in the following chapters.

The variable in JavaScript is used to store the values ​​in the script, so that the variables can be used to represent this value, one variable can be a number, text, or some other things.

JavaScript is a language that requires less stringent requirements for data type variables, so it doesn't have to declare the type of each variable, and the variable declares despite not necessary, but before using variables, it is a good habit. You can use a VAR statement to make a variable declaration. Such as: var men = true; // The value stored in the MEN is a Boolean type.

Variable Name: JavaScript is a case where case-sensitive language, so naming a variable is different and named computer is not the same. In addition, the length of the variable name is arbitrary, but the following rules must be followed: 1. The first character must be a letter (uppercase), or a downline (_) or a dollar value ($). 2. Subsequent characters can be letters, numbers, underscores or dollar characters. 3. Variable name cannot be a reserved word.

The statements provided by JavaScript are divided into the following categories: 1. Variable declaration, assignment statement: var. The syntax is as follows: VAR variable name [= initial value] Example: var computer = 32 // Definition computer is a variable and has an initial value of 32.

2. Function definition statement: function, return. The syntax is as follows: Function function name (parameter of the function belt) {Function Execution Part}

RETURN Expression / / Return statement indicates the value returned. Example: Function Square (x) {return x * x}

3. Conditions and branch statements: if ... Else, Switch. If ... ELSE statement completes the branch function in the program process block: if the conditions are true, the program executes the statement or statement block immediately; otherwise the program executes the statement or statement block in the ELSE. The syntax is as follows: if (condition) {execution statement 1} else {execution statement 2} example: if (result == true) {response = "You answer!"} Else {response = "You wrong!"} Branch statement Switch can take different processing methods according to different values ​​of a variable. The syntax is as follows: Switch (expression) {case Label1: Statement String 1; Case Label2: Statement 2; Case Label3: Statement 3; ... default: Statement 3;} If the value of the expression is provided Any statement does not match, and the statement in the default will be executed.

4. Circular statements: for, for ... in, while, break, continue. The syntax of the for statement is as follows: for (initialization section; conditional section; Update section) {Performing section ...} As long as the condition is established, the cyclic body is repeated. The For ... in statement is different from the for statement, and its loop is a range of objects all attributes or all elements of an array.

The syntax of the for ... in statement is as follows: for (variable in object or array) {statement ...}

The loop constant test conditions controlled by the While statement, if the condition is always established, it is loop until the condition is no longer established. The grammar is as follows: While (condition) {execution statement ...}

The BREAK statement ends the current various loops and performs the next statement of the loop.

The Continue statement ends the current loop and starts the next loop right away.

5. Object operation statement: with, this, new. The syntax of the with statement is as follows: with (object name) {execution statement} This is true: If you want to use a lot of properties or methods of an object, just write this object's name as long as the WITH statement is written, then Write the object name or method name directly written directly in the execution statement below.

The New statement is an object constructor that can define a new object with a new statement. The syntax is this: New object name = New real object name, for example, we can define a new date object: var curr = new date (), then, the variable Curr has the properties of the DATE object. The THIS operator always points to the current object.

6. Comment statement: ////*...*/. // This is a single line of comments / * This can be more comment ... * /

In JavaScript is an object-based programming, not a complete object-oriented programming. So what is the object? If you have learned some VB programming, it will not be unfamiliar with this noun. Popularly, the object is a set of variables, and the object provides a common property of a type of things for the identification of the data.

In JavaScript, you can use the following objects: 1. The object is automatically provided by the browser according to the content of the web page. 2. Built-in objects of JavaScript, such as Date, Math, etc. 3. Inherent objects on the server. 4. User-defined objects.

Objects in JavaScript are composed of two basic elements of the properties and methods. The property of the object refers to the background color, length, name, etc. of the object. The method of the object refers to the operation of the attribute, which is a function you belong to the object, such as the object, enabling the object to obtain a series of operations, etc.

For example, the car is regarded as an object, the color, size, brand, etc. of the car are called attributes, while launching, braking, turning, etc.

You can use this method to access the properties of the object: object name. Property name, example: mycomputer.Year = 1996, mycomputer.owner = "me".

You can use such a method to link objects to the function: object. Method name = function name or object. Properties. Method name, example: this.display = display, document.writeln ("this is method").

Look more or write some programs, you will understand the methods and properties of the object! Various properties and methods of each object, you can click on the reference!

The event is a mechanism for the browser to interactive operation. JavaScript's event handling mechanism can change the browser's way to operate, so that there is a web page with interactivity and easy to use.

The browser is called event processing in order to respond to an event.

The event defines various operations generated when the user interacts with the page, such as when you click a super connection or button, generate a click (click) operating event. The browser is waiting for the occurrence of interactive events in most of the program operation, and automatically invokes the event handler when the event occurs, and complete the event processing process.

Events can not only be generated in the user interaction, but also some of the browser's own action can also generate events. Example: When loaded into a page, a LOAD event will occur if a page is uninstalled, and an unload event will occur.

Incident, there must be three categories: 1. Events that cause the page between the pages are mainly super connection events. 2. Event browser's own events. 3. Event interacts with interface objects within the form.

All kinds of JavaScript events are available here.

转载请注明原文地址:https://www.9cbs.com/read-115724.html

New Post(0)