JavaScript Essential Knowledge

Source: Internet
Author: User

  1. Data type

    Strings: strings are used to store a series of characters, enclosed in quotation marks, with the same effect as single and double quotes.

    For example: Var a= "Bongly-ge"; var a= ' Bonly-ge '; The same effect, where Var is the definition of variable a, meaning that A is a variable, and now the value inside the string Bonly-ge,javascript can not appear in the vacuum of any one variable, it must be declared. Note: The use of quotation marks and mixed use, later there will be meaningless characters also need to declare, such as the late-stage timer will be used, the declaration of the way is Var tick; and other special declarations.

    Numbers: 1 2 3 4 ..... For example: var I = 5; var j = 2; alert (I+J); can also be var i,j,k; i=5;j=2; K=i+j; Alert (k); Note: The same effect, use the latter when the variables are separated by commas, there is no "=" after the alert sign.

    Boolean: Boolean value is two values, one is true (true) with a value of 1, and one is False (false) is represented by the value 0. Mainly used in the IF Judgment statement.

    Arrays: Arrays are collections of numbers and strings, or they can be mixed together. There are two ways of writing, one is Var z=new Array (1, "2", ' 3 ', "AB", ' ADC '), and the other is var z = [1, "2", ' 3 ', "AB", ' ADC '), and note that the brackets are separated by commas between the elements. Each element should have its own quotation marks, even if the strings are not omitted or otherwise, it must be in strict accordance with the prescribed format. Using alert (z[1]), you can eject the corresponding element, where the contents of the parentheses inside the z[] are the subscript of the array element.

    Object: Defines an object enclosed in curly braces with a name (name) and value (value) separated by commas, such as Var person{name: "bongly", Age: "$", Sex: "Male"}; Note: Value values are quoted in quotation marks, and single and double quotes are possible, but appear in pairs. There are two ways of calling, Age=person. Age Age =person[[age]; The first is commonly used, and the syntax is the variable = object. Name.

    Null: null value

    Undefind: Not defined

    Constructor/typeof: Type, we can check the type of the corresponding element by popping the TypeOf property to determine what type it is.

    Please refer to http://www.w3school.com.cn/js/js_datatypes.asp for more details.

  2. Operator

Arithmetic Operator: + addition if the plus sign between characters is a hyphen such as: Var a=2; var b=3; alert (A+B); The pop-up is 5,var a=2; var b= ' 3 '; alert (a+b); the popup is 23;

-mathematical operation minus for example: Var a=3; var b=2; Alert (A-B); The pop-up is 1,var a=3; var b= ' 2 '; Alert (A-B); The popup is also 1;

* Mathematical Multiplication Example: Var a=2; var b=3; alert (A*B); The pop-up is 6,var a=2; var b= ' 3 '; alert (a*b); The popup is also 6;

/mathematical Operations Division for example: Var a=6; var b=2; Alert (A/b); The pop-up is 3,var a=6; var b= ' 2 '; Alert (A/b), the Popup is also 3, the popup is the quotient.

% mathematical operations take the remainder for example: Var a=6; var b=2; alert (a%b); The pop-up is 0,var a=7; var b=2; alert (a%b); The popup is 1, so the remainder is popped.

+ + increments-decrements the use of + + or-to achieve the loop, to achieve their own sliding scale or decrement to achieve the loop, such as i++ means i=i+1; if the initial value of I is 2, after i++, I is the value of 3, if the initial value of I is 2, after i--, I is the value of 1.

Comparison operator: = equals sign (used to assign value); = = equals number (for if judgment); = = = Absolute equals (used if judgment except for the value of the attribute is equal, generally not);! = does not equal the return value to a Boolean type; the!== is not equal to the number and type; > Greater than < Less than <= is less than or equal to >= greater than or equal

Logical operators: and (with) && (a && b) A and B two conditions are true or (not) | | (A | | b) A and B two conditions meet one condition that is true negation! For example: x=3,y=6;! (x==y) is true.

Assignment operator: = equals sign is used to assign a value.

Please refer to http://www.w3cschool.cn/javascript/js-comparisons.html for more details.

    1. Grammatical structure

      Conditional if (judging condition) {condition is set to execute statement 1} else{condition does not establish execution statement 2}; if (judging condition) {The condition establishes the execution statement}; Note that if statements are executed only when they are true, there is no else.

      Trinocular X>y?alert ("1"): Alert ("2"); The three-purpose notation is shorthand for the if () {}else{} statement. But there are also differences, if the statement does not return a value, the Trinocular statement has a return value, for example: Var i=1; if (i>1) {i=0;} Else{i++};alert (i); pop-up is 2;var i=1; if (i>1) {i=0;} Else{++i};alert (i); the popup is also 2; in three-mesh statements var I=1; I=i>1? 0:i++; alert (i); the popup is 1; in the three-mesh statement, Var I=1; I=i>1? 0:++i; alert (i); the popup is 2. Summary: The three-mesh operation has a return value, and if else does not have a function value. That is, the three mesh is the first return value in the operation, and if else does not return a direct operation of the result.

      Branch switch (N) {case label 1: Code snippet 1; break;case tag 2: Code snippet 2; break;}; In the switch statement, n is usually a variable and matches the case label inside the curly brace, executes the corresponding code snippet after the match succeeds, and then jumps out of the switch statement. Note the syntax formatting inside the curly braces.

      Loop for (define variable assignment; condition judgment; Execute 3) {execute function}; Often used, must be mastered.

      Error handling try{//run code here} catch (Err) {//Handle error here} http://www.w3cschool.cn/javascript/js-errors.html

      Please refer to http://www.w3cschool.cn/javascript/wopi12hp.html for more details.

JavaScript Essential Knowledge

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.