JavaScript notes four

1. Operators
Logical Operators
!
- a non-Boolean operation can be inverted, true becomes false false to true edge
-! When use of non-boolean, will first convert Boolean then inverted
- we can be used to convert other data types Boolean!

&&
- && can symbol values on both sides of the operation
- at both ends, only the value is true, will return true. As long as there is a false returns false.
- and is a short and, if the first value is false, then the second value is not checked
- for non-Boolean value that converts to a Boolean operation is then done, and return the original value
- Rule:
1 If the first value is false, the first value is returned
2. If the first value is true, the second value is returned

||
- || can be symbol values or both sides of the operation
- only at both ends when are false, it will return false. As long as there is a true, it returns true.
- either a short circuit or, if the first value is true, the second value is not checked
- for non-Boolean value that converts to a Boolean operation is then done, and return the original value
- Rule:
1 If the first value is true, the first value is returned
2. If the first value is false, the second value is returned

assignment operator
=
- right value can be assigned to the left of the variable symbols

+ =
- a + = 5. 5 corresponds + A = A
- STR var = "Hello"; STR + = "World";

- =
- A - =. 5-A =. 5 corresponds to A

* =
- A * =. 5 corresponds = a *. 5 a

/ =
- a / a = =. 5 corresponds to the a /. 5

% =
- a. 5% = a = a% 5 equivalent


relational operators
- relationship between the size of the operator is used to compare two values relationship
>
> =
<
<=
- rules and mathematical relationships consistent operators used to compare the relationship between the two values,
if the relation holds returns true, false if the relationship is not established.
- If the two values of the non-numerical comparison, will convert Number before comparison.
- If the two compared values are strings, this time will be encoded Unicode string comparison, rather than being converted to Number.

Equality operator
==
- equal, determination about whether the two values are equal, returns true if equal, if unequal returns to false
- two equal values automatically type conversion, when comparing different types, it is converted then the same type of comparison,
equal conversion it also returns true after
=!
- ranging, determines whether the left and right two values unequal, returns true if unequal, it returns false if equal
- automatic ranging will do type conversion.

===
- congruent, it is determined whether the left and right two congruent values that are equal, and the like, but it is not automatic type conversion,
if the values of two different types, the process directly returns to false

==!
- insufficiency , and the like vary, but it is not automatic type conversion, if the two values of different type, it will return directly to true

special value:
- null and undefined
- undefined since derived from null, so null == undefined will return true.
But null === undefined returns false.

- NaN
- NaN is not equal to any value, the report itself // false NaN == NaN

- to determine whether a value is NaN
- use isNaN () function

ternary operator:
:?
- Syntax:? 1 conditional expressions statement: statement 2;
- perform the process:
first determination of the condition expression is evaluated,
If the determination result is true, the execution statement 1, and returns the execution result
if the determination result is false, the execution statement 2, and returns the result of execution

priority:
- and mathematics as, JS the operator also has a priority,
such as multiplication and division and subtraction before and after the first or after
- priority table can reference a particular priority, the higher on the table by priority,
the higher priority of the priority calculation, the same priority, to the left Right calculations.
- a priority memory is not necessary, if in doubt to the use of () to change the priority.

2. The flow control statements
- is self-executing program down order,
through the process control statements may change the order of execution of the program, or execute a repeated program segment.
- Category:
1. conditional statement
2. The conditional branch statement
3. Loops

conditional statement
- also referred to as a conditional statement if statement
- a syntax:
if (conditional expression) {
statements ...
}

- execution flow:
if when the statement is executed, will first conditional expressions are evaluated is determined,
if the value is true, if the statement is executed
if the value is false, not performed

- two syntax:
if (conditional expression) {
statements ...
} else {
statement ...
}

- perform the process:
if ... else statement when executed, will determination condition expression is evaluated,
if the value is true, if the statement is executed
if false, the execution else statement

- syntax three:
IF (conditional expression) {
statements ...
} the else IF (conditional expression) {
statements ...
} the else IF (conditional expression) {
statements ...
} else if (conditional expression) {
statements ...
} else {
statements ...
}

- execution flow
- if ... else if ... else statement when executed, sequentially from top to bottom for the conditional expression evaluation judgment,
if the judgment result is true, if the statement is executed after this, performed after the end of the statement is completed.
If the determination is false, the judge continued down until you find is true so far.
If all of the conditional expressions are false, the statement after else is executed


Guess you like

Origin www.cnblogs.com/Jiang-jiang936098227/p/11595436.html