Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the JS operator

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to use the JS operator", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use the JS operator" this article.

Arithmetic operator

Perform arithmetic operations on variables and constants of numerical types.

It is also the simplest and most commonly used operation symbol.

The four mixed operations follow the principle of "multiplication and division first and then addition and subtraction".

The positive or negative result of the modular operation depends on the symbol of the module (the number to the left of%).

Try to avoid using decimals for calculation, sometimes the accuracy of JavaScript may lead to deviation of the results.

"+" and "-" can also represent positive or negative numbers in arithmetic operations.

The operator (+ or -) is placed in front of the Operand, performing self-increment or self-subtraction operations, followed by other operations. If the operator is placed after the Operand, other operations are performed first, followed by self-increment or self-subtraction.

The increment and decrement operators operate only on numeric and Boolean data, treating Boolean true as 1 and false as 0.

String operator

In JavaScript, as long as one of the two data in the "+" operation is of character type, "+" represents the string operator and is used to return the concatenated string of the two data.

Assignment operator

Is a binary operator, that is, it has two operands.

It assigns the value on the right of the operator to the variable on the left.

Be careful

"=" is an assignment operator, not a mathematical equality.

A single assignment statement can assign values to multiple variables.

The associativity of the assignment operator is from right to left.

Comparison operator

Used to compare two values or variables.

The result is a true or false of Boolean type.

Be careful

When different types of data are compared, they are automatically converted to the same type of data first and then compared. The operators "=" and "!" operators compare only if the values are equal. The operators "=" and "!" To compare whether the value and its data type are equal.

Logical operator

It is a symbol used for logical judgment in program development. The return value type is Boolean.

The associativity of logical operators is from left to right.

When concatenating two expressions with "& &", if the expression on the left has a value of false, the expression on the right will not be executed, and the logical operation will result in false. (short circuit)

When concatenating two expressions with "| |", if the expression on the left has a value of true, the expression on the right will not be executed and the logical result will be true. (short circuit)

Logical operators can operate on expressions that result in Boolean values.

Ternary operator

A ternary operator is an operator that requires three operands, and the result of the operation is determined according to a given condition.

First find the value of the conditional expression.

If true, the execution result of expression 1 is returned.

If the value of the conditional expression is false, the execution result of expression 2 is returned.

Bit operator

Is a symbol that operates on each bit of a binary number.

It operates specifically for the numbers 0 and 1.

Be careful

The JavaScript median operator can only operate on numeric data. Before performing a bit operation on a number, the program converts all operands into binary numbers, and then operates bit by bit.

Operator precedence

Operators in the same cell have the same priority.

The left union direction indicates that the order in which sibling operators are executed is from left to right.

The right combination direction indicates that the execution order is from right to left.

Add: parentheses () have the highest priority. For example, the output of 4 + 3 * 2 is 10, and the output of (4 + 3) * 2 is 14.

These are all the contents of the article "how to use JS operators". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report