Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the JavaScript operator

Shulou Source: shulou.com Published: 2022-06-03 06:46:58 10月01日 Update

This article mainly introduces "how to understand the JavaScript operator". In the daily operation, I believe many people have doubts about how to understand the JavaScript operator. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to understand the JavaScript operator"! Next, please follow the editor to study!

Operator

1 arithmetic operator

Outline: the operator for addition, subtraction, multiplication and division, and the calculation of the remainder.

Operator: +, -, *, /,% (operation to take the remainder)

Note: floating point (decimal) operations may cause accuracy problems when performing arithmetic operations

2 increasing and decreasing operators

Operators: + +,-- (averse +, amure -, + + a,-- a)

/ / the pre-increment operator var num = 1 / or num++console.log (num) / / the result is 2 / / + + num, so num = num+ 1 hand / pre + + is to do self-increment first and then to do other operations / / pre-decrement operator var num = 1 Mattel num / or num--console.log (num) / / the result is 0 /-- num is equivalent to num = num- 1 jump / front-- is to do self-subtraction before doing other operations

3 comparison operator

Operator: >

< , >

=,

< , >

=, 18 & & (num=998); / / because age > 18 is not true, the logic and result is false / / so when the logic and calculation is complete, the subsequent num=998 will no longer run

Logic or (| |):

As long as a condition is true, the result of the expression is true, and only if all the conditions are not true, the result of the expression is false.

Interruption of logical OR:

Var age= 18 num;age = = 18 | (num=998); / / because the age==18 is established, the logic or the result is true / / so when the logic or calculation is complete, the subsequent num=998 will no longer run

Logic is not (!): take true as false and false as true.

Var a = 5 ×! (a > 1) / / an equals 5, so a greater than 1 is true (true), so this expression is false because it is reversed.

5 Ternary operator:?:

It can be understood as a simplified way of writing two branches of if.

Grammatical structure:

Expression 1? Expression 2: expression 3

When expression 1 is true, expression 2 is executed

When expression 1 is not valid, expression 3 is executed

The result of the operation is that if an is 3, var b is greater than 2, return b to a, and return c to a for false, because b is less than 2, so return c to a. The study on "how to understand the JavaScript operator" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Operations operators expressions results logic conditions data learning that is time type run same priority only case more problem help different Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Xiaomi Docker Shulou Tech Info Shulou Information