operator

100 * "20" string to number

5 * "ss" NAN "ss" convert number to return NAN

      Any number with NAN +-*/ returns NAN

5 / NAN NAN Multiplication

0/0 NAN Zero division by zero returns NAN

10/0    Indefinity

-10/0     -Indefinity

 

++i

i++

var i = 11;

var i2 = ++i+3 //i2=15 The self-addition operator is added first and then participates in the expression

var i3 = (i++)+3 //i3=14 The self-addition operator first participates in the expression (i++)+3 operation and other expressions to calculate the result and the assignment is completed, and then execute i = i+1

 

unary addition

+"23"  => 23

+a //Converting a variable into a number is more convenient than the number() function

1+"999" => "1999" Consider the operation after limited string chaining

 

Subtraction operator only mathematical subtraction does not have string concatenation

var i = 3-"2"  => 1

 

Boolean operator

Logical NOT !

logical or &&

logical AND ||

relational operator

3>"2" true

are all numerical values, compare numerical values

If they are all strings, compare the encoding

A number and a string are converted to numbers for comparison

Ternary operation

  var b = a>3?2:1

 

Operator Practice Questions

  var a = "1",b=3,c=true;

  a>b=> false

  a>=c => false character 1 character t encoding comparison is not converted to digital comparison

  !b => false

  a+b => "13"

  b+c => 4

  b-a=>2

  b&&a => true

  !(a||b) => false

  +c=>1

  ++a+c =>2+c =>true

  6/0  infinity

  NAN * 0 NAN

  b>c?++a:c => ++a adds itself first and then participates in the expression

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324713509&siteId=291194637