JS Basic Two

Source: Internet
Author: User
Tags arithmetic operators

# # While Loop statement

1. The difference from the IF statement: The IF statement executes only once, while the while statement executes multiple times.

2, usage: After each execution of a block of statements, will jump back to check the parentheses in the Boolean value, if True, then will execute the statement block once, until a false stop encountered.

3. Note

```

while (true) {

Console.log (' Heillo ')

}

```

This code is a dead loop, the browser will always load, JS should avoid the class of code.

4, the While statement can appear break, the end of the entire Whlie statement, break can only be written in the statement block while, cannot be written separately.

5, continue can also appear in the while, it will only end the current while through the bad, the back of the loop continues. Note: It does not work when the continue is placed at the end of a while statement block.

# # FOR Loop statement

```

for (initialize; test; increment) {

Console.log ();

}

```

# # # for Loop code Execution order

1. Execute the first statement in parentheses.

2. Judge the Boolean value of the second statement in the parentheses, true to execute the Curly brace statement block, false to end the entire for loop.

3. After each execution of the block of statements in curly braces, the third statement in the parentheses is executed.

4. After each execution of the third statement in the parentheses, skip to step 2nd.

# array [,,,]

```

var arr=[1,2,3,4,5,100,200,1000];

Console.log (arr.length); The length of the array

Console.log (Arr[0]) The first item of an array

```

# # JS three ways to introduce (embedded (with less), inline, external) 1, inline: (written in the head tag) "' <script type=" Text/javascript "> Console.log (" Hello World ");< /script> ' 2, Outreach: (written in the body content of the last side, easy to optimize the user experience, reduce load time, first load out the structure and style of the Web page, and finally load the behavior section) "' <script type=" Text/javascript "src= "JS file path (relative path)" ></script> "# # declaration variable var A; (declare variable a) a=10; (a assignment of 10) abbreviated to the Var a=10;## data type (a total of 5) is a numeric type (number), a string type (String), a Boolean value type (Boolean), null (NULL), and undefined (undefined), the first three have meaning, The latter two have no meaning.   # # # value type ' var A;   a=20; ' # # # string character type ' ' var A; A= ' Hello '
Note: The string outside with ' and ' can be, but ' more professional. A= ' what\ ' s\ ' This ' is the translation, that is, the original meaning of the conversion; \ n for newline characters # # Boolean value type TRUE or false## variable name rule-the first character can be any Unicode uppercase and lowercase letters, and the dollar sign ($) and underscore (_). -The second character, followed by the character, can also be used as a number. -You cannot use reserved words as variable names or symbols
##### *javascript reserved word * ' abstract ' ' Boolean ' ' Break ' ' byte ', ' case ' ' catch ' ' char ' ' class ' ' const ' ' Continue ' debugger ' Default ' delete ' ' do ' double ' else ' enum ' ' export ' ' extends ' ' false ' final ' finally ' float ' for ' function ' goto ' I F ' Implements ' ' Import ' ' in ' instanceof ' int ' interface ' long ' native ' new ' ' null ' ' package ' ' private ' ' protected ' p Ublic ' return ' ' short ' ' Static ' ' super ' ' Switch ' synchronized ' "This" ' throw ' ' throws ' transient ' true ' try ' typeof ' var ' void ' ' volatile ' while ' with ' # operator # # unary operator (only one operand) # # increment operator (+ +) decrement operator (-) a++ and ++a are incremented, but with different meanings-the increment operator is placed in front of the operand (+ + A), the value after the operand plus 1 as the return value. -The increment operator is placed after the operand (a++), and the operand is appended with a previous value as the return value.
"' Var a=10;  var b= (a++) + (++a);  Console.log (A, b); 12 22 "
# # # unary minus operator (-) takes the opposite number of operands, and other types of data can be converted to numeric types. # # # Unary plus operator (+) takes the operand itself, and other types of data can be converted to numeric types. # # # typeof operator returns a string that is the name of the operand's type. # # Two operator # # # arithmetic operator ' + '-' * '/'% '
Note: Arithmetic operators have no restrictions on the type of operands, and are converted to numeric types except for +.
"' Console.log (10+20); 30 arithmetic addition operator Console.log (+ + ' 20 ') 1020 string concatenation operator ' rule: as long as one or 2 of the 2 operands is a string, then the + is the concatenation operator. # # logical Operator # # logical non-operator (unary) (!) operand) Usage:-The Boolean value of the operand-the case where the return value is the opposite of a Boolean value
Note: The return value is a Boolean value any type can be converted to a Boolean value-if the object-true-an empty string-false-a non-empty string-true-value 0-false-any non-0 value (including infinity)-true-null-false- undefined-false-nan-false## #逻辑与操作符 (&&)
Usage: Boolean for the first operand, and if Boolean is true, the return value is the 2nd operand, and if the Boolean value is False, the return value is the 1th operand. -Note: The return value can be any type of data.
# # # Logical OR operator (| |) Usage: Boolean for the first operand, and if Boolean is true, the return value is the 1th operand, and if the Boolean value is False, the return value is the 2nd operand. -Note: The return value can be any type of data.
# # # Short-circuit operation in the operator and OR operator, if the first operand is already able to determine the result of the final return, then the second operand is not evaluated. "Var A=10;var b=true&& (a++) Console.log (A, b); One to ten "" Var A=10;var b=false && (a++) Console.log (A, b); Ten false ""
# # Relationship Operations Fu Xiao (' < '), greater than (' > '), less than equals (' <= '), greater than equals (' >= ') These relational operators are used to compare two values and compare the same rules as we learned in math class. These operators will return a Boolean value # # equality operator (return value is a Boolean) equality operator (' = = '), inequality operator ('! = '), equality operator (' = = = '), unequal operator ('!== ') # # # Equals and inequality = # First converted to the same type and then compare # # # # Congruent and non-congruent = only comparison without conversion type (preferred) # # The simple assignment operator of the assignment operator is represented by the equals sign (' = '), and the function is to assign the value on the right to the variable on the left.
# # conditional operator (trinocular operator) ' Boolean_expression? True_value:false_value '
Usage: The first operand is true, the return value is the second operand the first operand is false, the return value is a third operand

The precedence of the # operator
| Operator                                      | Description                         | | ---------------------------------------- | -------------------------- || ' + + '--'-'-' + ' ~ '! ' delete ' new ' typeof ' void ' | Unary operators, return data types, object creation, undefined values     | | ' * '/'% '                              | Multiplication, division, modulo                   | | ' + '-' + '                              | addition, subtraction, string connection                | | ' << ' >> ' >>> '                       '   & nbsp;| Shift                         || ' < ' <= ' > ' >= ' instanceof '           | Less than, equal to, greater than, greater than or equal to, instanceof | | ' = = ' ' = ' = = = = '!== '                    | Equal, not equal, strictly equal, not strictly equal          | | ' && '                               &NBS P     | Logic and                        | | \\\\| Logic or                        | | '?: '                                 &NBSP ;   | Conditions                         | | "= '                                      | Assignment,                  | operation assignment
The following table lists the JavaScript operators by priority from highest to lowest.   Operators with the same precedence are evaluated in order from left to right.   The conditional statement JavaScript provides the ' if ' structure and ' switch ' structure to complete the conditional judgment.   # # ' If ' struct syntax: ' JavaScript if (expression 1) {expression 2;   } expression 3; * * * *: If expression 1 is established, Expression 2 will not be executed, execution expression 3 # # If...else ...   Statement syntax: "' JavaScript if (expression 1) {expression 2;   } else {expression 3;   } expression 4;   "* * Description * *: Program judge expression 1, set up an execution expression 2, do not set the execution Expression 3, and then execute the expression 4 # # If...else If ..." "JavaScript if (expression 1) {expression 2;   } else if (expression 3) {expression 4;   } else if (expression 5) {expression 6;   } else {expression 7;   } expression 8; ```
# # Switch structure ' ' javascript var a = 1;   Switch (a) {case 1:console.log (1);       Break   Case 2:console.log (2);       Break   Case 3:console.log (3);       Break   Default:console.log ("Default"); }

JS Basic Two

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.