js assignment, relationship, equality, conditional operator

Assignment operator

=
The value on the right side of the symbol can be assigned to the variable on the left side of the symbol
+=
a += 5 is equivalent to a = a+5
-=
a -= 5 is equivalent to a = a-5
*=
a * = 5 etc. Equivalent to a = a * 5
/=
a /= 5 is equivalent to a = a/5
%= take the remainder
a %= 5 is equivalent to a = a%5

Relational operator

The relational operator can be used to compare the size relationship between two values.
If the relationship is established, it will return true, if it is not established, it will return false
.

  • Determine whether the value on the left side of the symbol is greater than the right side
  • If the relationship is established, return true, otherwise return false
    ">=" greater than or equal to
    • Determine whether the value on the left side of the symbol is greater than or equal to the right side
    • If the relationship is established, return true, otherwise return false
      <less than sign
  • Determine whether the value on the left side of the symbol is less than the right side
  • If the relationship is established, return true, otherwise return false
    <= less than or equal to
    • Determine whether the value on the left side of the symbol is less than or equal to the non-numeric value on the right side
    • When comparing non-numeric values, it will be converted to numbers and then compared
    • If the value on both sides of the symbol is a string, it will not be converted to a number,
      but the Unicode encoding of the characters in the string will be compared separately
    • When comparing character codes, it is compared one bit by bit.
      If the two bits are the same, the next bit is compared, so use it to sort English.
      For example:
      console.log("abc">"a") The result is true

Unicode encoding

			- 在js中使用 \u十六进制编码
				- 在网页中使用Unicode编码  &#编码;这里的编码需要转化为十进制

Equality operator

The equality operator is used to compare whether two values ​​are equal, if they are equal, it returns true, otherwise it returns false.
Use == to do the equality operation.
When using == to compare, if the types are different, it will automatically perform type conversion and convert it to The same type then compare

  • undefined is derived from null, so when these two values ​​are equal, it will return true
  • NaN is not equal to any value, including itself
  • To determine whether a value is NaN, use the isNaN() function.
    If the value is NaN, return true, otherwise return false

Use != to do unequal operation
-unequal to judge whether two values ​​are not equal, return true if they are not equal, otherwise return false
-unequal will also perform automatic type conversion on variables, and return true if they are not equal after conversion. Otherwise it returns false
=== congruent
-used to judge whether two values ​​are congruent, it is similar to equality, the difference is that automatic type conversion will not be performed
-if the two values ​​are of different types, it will directly return false
!== incomplete Equal
-used to determine whether two values ​​are not equal, it is similar to inequality, the difference is that automatic type conversion is not performed
-if the two values ​​are of different types, it will directly return true

Conditional operator

Conditional operator is also called ternary operator

Grammar:
Conditional expression? Statement 1: Statement 2
When the conditional expression is not a Boolean value, it will first be converted to a Boolean value and then evaluated.
The flow of execution:
-First, the conditional expression is evaluated.
If the value is true, then statement 1 will be executed. And return the execution result; if
the value is false, then execute statement 2 and return the execution result.
var a = 20;
b = 50;
var max = a> b? a: b;
console.log("max="+max); the result is 50

It can also be used to compare the size of numbers
var a = 20;
b = 50;
c = 60;
var max = a> b? A: b;
max = max> c? Max: c;
console.log(“max=”+ max); the result is 60

Guess you like

Origin blog.csdn.net/weixin_48769418/article/details/107810465