JS a summary

Source: Internet
Author: User
Tags natural logarithm square root

I. JS data types and variables

JavaScript has six types of data. The main types are number, string, object, and Boolean, and the other two types are null and undefined.

String String type: The string is indicated by single or double quotation marks. (use single quotation marks to enter a string containing quotation marks.) ) such as: "The cow jumped over the moon."

Numeric data type: JavaScript supports integers and floating-point numbers. Integers can be positive, 0, or negative, floating-point numbers can contain a decimal point, or they can contain an "E" (uppercase and lowercase, which means "power of 10" in scientific notation), or both.

Boolean type: The possible Boolean value has true and false. These are two special values that cannot be used as 1 and 0.

Undefined data type: A value of Undefined refers to a value that has been previously assigned to a variable after it has been created, but not given a value.

Null data type: A null value is no value and nothing is represented.

Object type: In addition to the various common types mentioned above, objects are an important part of JavaScript, which is described in detail later in this section.

In JavaScript, variables are used to hold the values in the script so that they can be represented in a variable where this value is needed, a variable can be a number, a text, or something else.

JavaScript is a language that is less stringent on data type variables, so it is not necessary to declare the type of each variable, although the variable declaration is not necessary, but it is a good practice to declare it before using the variable. You can use the Var statement to make a variable declaration. such as: var men = true; The values stored in men are of type Boolean.

Variable naming: JavaScript is a case-sensitive language, so naming a variable computer and naming it 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 (either uppercase or lowercase), or an underscore (_) or a dollar sign ($).
2. Subsequent characters can be letters, numbers, underscores, or dollar symbols.
3. The variable name cannot be a reserved word.

/* Why ask Hovertree.com * *

Two. JS statement and syntax

The statements provided by JavaScript fall into the following major 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 (parameters with functions)  

function Execution part  


The return expression//return statement indicates the value that will be returned.  
Example: function square (x)  

return x*x 
}

3. Conditions and Branching statements: If...else,switch.       The
If...else statement completes the branching function in the program flow block: If the condition is true, the program executes the statement or block of statements immediately following the condition, otherwise the program executes the statement or block of statements in the else. The syntax is as follows: if (condition)  

Execute statement 1 
}else{ 
Execute statement 2 

Example: if (result = = True)  

response = "You answered right!" " 
}else{ 
Response =" You're wrong! " " 


Branch Statement switch can take a different approach based on the different values of a variable.   The
syntax is as follows: switch (expression)  

Case LABEL1: statement string 1; 
Case Labe        L2: statement string 2; 
Case LABEL3: statement string 3; 
...  
Default: statement string 3; 

If the value of the expression does not match any of the statements provided in the program, the statement in default will be executed.

4. Loop statement: for, For...in,while,break,continue.
The syntax for the FOR statement is as follows: for (initialization part; condition part; Update section)

Executive section ...

As long as the condition of the loop is established, the loop body is repeatedly executed.
The for...in statement is a little different from the for statement, and it loops through all the properties of an object or all the elements of an array.

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

Statement...
}

The continuous test condition controlled by the while statement, if the condition is always true, loops until the condition ceases to be true.
The syntax is as follows: while (conditional)

Execute statement ...
}

The break statement ends the current various loops and executes the next statement of the loop.

The continue statement ends the current loop and immediately begins the next loop.

5. Object Operation statement: With,this,new.
The syntax for the WITH statement is as follows:
With (object name) {
EXECUTE statement
}
The effect is this: if you want to use many of the properties or methods of an object, simply write out the name of the object in the () of the WITH statement, and then direct the property name or method name of the object to the following execution statement.

The new statement is an object constructor that you can use to define an object.
The syntax is this: the new object name = The real object name
For example, we can define a new Date object like this: Var curr= new Day (), and 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 comment
/* This can be a multiline comment .... */

Three. js object properties and methods.

In JavaScript, it is object-based programming, not full object-oriented programming.

So what is the object? If you have learned some VB programming, this noun must not be unfamiliar. In layman's words, the object is a set of variables, the object provides a consistent organizational means for the data, and describes the common attributes of a class of things.

In JavaScript, you can use the following types of objects:
1. Objects that are automatically provided by the browser based on the content of the Web page.
2.JavaScript of built-in objects, such as Date,math.
3. Intrinsic objects on the server.
4. User-defined objects.

The objects in JavaScript are made up of two basic elements of properties and methods. The object's properties are the object's background color, length, name, and so on. An object's methods are the operations that are performed on a property, such as an object's own function, such as rounding an object, giving the object the focus, getting the object to a random number, and so on.

For example, the car as an object, the car's color, size, brand and so called attributes, and start, brake, turning, etc. is called the method.

You can use this method to access the object's properties: Object name. Property name, example: Mycomputer.year=1996,mycomputer.owner = "Me".

You can use this method to associate a method of an object with a function: an object. Method name = function name or object. Property. Method Name, Example: This.display=display,document.writeln ("This is Method").

If you look at or write more programs, you will understand the meaning of the object's methods and properties!

Four. Handling of JS Events

Events are a mechanism by which browsers respond to user interaction, and JavaScript's event-handling mechanism can change how browsers respond to user actions, creating interactive and easy-to-use web pages.

The process that a browser takes to respond to an event is called event handling.

Events define the various actions that occur when a user interacts with a page, such as when a hyperlink or button is clicked, resulting in a click action event. The browser waits for most of the time the program is running for an interactive event to occur and, when the event occurs, automatically invokes the event handler to complete the event handling process.

Events can be generated not only during user interaction, but also by some of the browser's own actions, such as when loading a page, a Load event occurs, a unload event occurs when a page is unloaded, and so on.

To sum up, there are three main categories of events that must be used:
1. Events that cause jumps between pages, mainly hyper-connect events.
2. Events that are caused by the event browser itself.
3. Events interact with the interface object inside the form.

Other:

Javascript Basics
One, variable
var MyBook;
mybook=5;
Variable names require a letter or _, and cannot contain spaces
Common types are: string, numeric, Boolean, and object type.
var num=6
b= (3>5)
False true
Ii. Expressions and operators
1. Comparison operators
= = = > < >= <=
2. Operator operator
+   -   *   /   %   ++   --


3. Logical operators
With &&, or | | Non -!
4, bitwise operator
& | ^ (XOR) ~ << >> >>> (fill 0 right shift operator)
5. Assignment operator
=
+=   -=   *=   /=
&= |= ^=
<<= >>= >>>=


6. Other operators
Conditional operator: (condition)? Value 1: Value 2 a=5 b=6 c= (a>b)? a-b:a+b
New operator Var
Com=new Array ("Zhang", "Li", "Wang", "Chen")
COM[2]
Delete operator Delete Com[2]
7.
Third, the statement
1. Conditional statements
(1) If......else
if (mark>60)
S= "Pass"
Else
S= "Fail"
(2) tch case label 1: code block 1;break;
Case Label 2: code block 2;break;
............
Case Label N: code block N;break;
Default: code block;
}
(3)
2. Circular statements
(1) For statement
for (initial expression; loop condition; increment expression)
{code block}
(2) While statement
while (loop condition)
{code block}
(3) Do......while statement
do{
code block
} while (loop condition)


(4) Label statement
Label: code block
(5) Break statement
Jump out of a looping statement or tch
Break label jumps out of the code block identified by the label


(6)
3. Other statements
(1) for......in statement [forin.htm]
For (variable in object) {
Code block}
(2) with (object) {
Code block}
(3) Notes
Comment Line/* * *


(4) return
4.
Iv. functions
1. Definition of function
Function name (argument list)
{code block
}

--How to ask
--Release time: 2015-12-3 1:31:00

--

2, function call  
     function name (argument list)  
3, JavaScript global function  
(1) eval (string)  
executes the string  
(2)    parseint (string, [radix])    parsefloat (String)  
var s= "3.14"  
var j=parseint (s)  
var k=parsefloat (s)  
         parseint ("2B", +) = 
(3) IsNaN (expression): not a numeric  
(4) Number (object) and String (object)  
Var n=new numbers (20)  
document.write (n.tostring)  
(5) Escape (string) and Unescape (string) convert the message string format to ASC code format  
4. Method  
(1) scrolling window scroll ()  
   Scroll (x, y): Move to a point in the window, the upper-left corner is 0,0     [ winscroll.htm] 
(2) sets the delay settimeout ("expression", time) Time:   in milliseconds,
(3) to clear the delay cleartimeout ("delay number")  
For example: ID =settimeout ("disp ()", "   "),
     cleartimeout (id)  
(4)

Five, Object   in Javascript,
1, build custom object  
Method 1: Object ={Property 1: Property value 1, Property 2: Property value 2 ... Attribute N: Attribute value n} 
   Method 2: Define the constructor first and then new to create the object instance.  
     For example: function car (thecolor,thenumber,thewheels)  
            {this.color=thecolor; 
              this.number=thenumber; 
              this.wheels=thewheels;  }

var mycar=new car ("RED", "13245", 4);
2. Methods for defining objects [oop.htm]
function Reportinfo ()
{var information=new string;
information= "COLOR:" +this.color+ "<BR>";
information+= "Number:" +this. number+ "<BR>";
information+= "Wheels" +this.wheels;
Window.document.write (information);
}

3. JavaScript Core Language Object
(1) Array objects (arrays)
Build array: var st=new array ("Zhang", "Wang", "Li", "Chen");
var st1=new Array (4)
Accessing array elements: St[2]
property of the Array object length (length) [forin.htm]
Method sort () sorts by ASCII ([comparison function name]) [sort.htm]
Compare function return values (a versus B) <0 B is in front of a
=0 Keep the original order
>0 A is in front of B.
Reverse () Element reversal order
Join (delimiter) converted to string

(2) Strings object (String)
Property: Length
Method: Convert toUpperCase () to uppercase
Convert toLowerCase () to lowercase
IndexOf (string, starting position) returns the position of the substring in the string, or 1 if not.
LastIndexOf (string, starting position) returns the last position of the substring in the string
CharAt (position) returns the letter of the subscript position in the string
substring (position 1, position 2) Return position 1, position 2 string
Split (delimiter) decomposes the array element by delimiter
The following is a format string method [Str.htm]
Big () Blink () bold () fixed () FontColor () fontsize () italics () Small ()
Strike () Sub () Sup ()

--How to ask
--Release time: 2015-12-3 1:31:00

--

(3) The Date object (date)
Create Date Object
var object name =new Date (parameter)
var thedate=new Date ()
var thedate=new Date (1999,1,1)
Method: GetYear ()
GetMonth ()
GetDate ()
GetHours ()
Getminutes ()
Getseconds ()
Setyear (year)
Setmonth (month)
SetDate (date)
Sethours (number of hours)
Setminutes (number of minutes)
Setseconds (number of seconds)
GetTime (milliseconds) received January 1, 1970 0:0 0 seconds start of the Hao second
SetTime (number of milliseconds)
(4) Math object (Math)
Property: Pi 3.14159265
Square root of SQRT2 2 1.414
Natural logarithm of LN2 2 0.693147
E 2.718281828459
Natural logarithm of LN10 10 2.302585
LOG2E the logarithm of the base e of 2 to 1.442695
LOG10E the logarithm of the base e of 10 to 0.4342944819
Square root of Sqrt1-2 0.5 0.7071
Method: Min (value 1, value 2)
Max (value 1, value 2)
Round (numeric) rounding
Ceil (value) returns the minimum integer negative value of the >= parameter 0 (rounding up)
Floor (value) truncated rounding (rounding down)
Random number () 0-1
sqrt (numeric value) returns the square root of a number
ABS (value) take absolute value
ACOs (value) arccos inverse cosine
ASIN (value) anyway chord
Atan (value) anyway cut
cos (value) cosine
Sin (value) sine
Tan (value) tangent
Atan (x, y) calculates a polar angle, sandwiched between the X positive half axis and the Y
Y power of the POW (x, y) x
The natural logarithm of log (x) x
EXP (x) e x Time Square

Recommendation: http://www.cnblogs.com/roucheng/p/jstoupiao.html

JS a summary

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.