Operators include: 1. Arithmetic operators, including " ", "-", "*", etc.; 2. Assignment operators, including "=", "=", "-=", etc.; 3. , Comparison operators, including "==", "===", etc.; 4. Logical operators, including "&&", "||", etc.; 5. Bit operators, including "&", "|", etc. .
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
JavaScript operator (operator)
In JavaScript, operators are used to assign values, compare values, perform arithmetic operations, etc.
Arithmetic operators
Arithmetic operators are used to perform operations on two variables or values.
Assign y = 5, the following table will explain to you the use of arithmetic operators:
Operator | Description | Example | y value | x value |
---|---|---|---|---|
Addition | x = y 2 | y = 5 | #x = 7 | |
- | Subtraction | x = y - 2 | y = 5 | #x = 3 |
* | Multiplication | x = y * 2 | y = 5 | #x = 10 |
/ | Division | x = y / 2 | y = 5 | x = 2.5 |
remainder | x = y % 2 | y = 5 | x = 1 | |
increment | x = y | y = 6 | x = 6 | |
y = 6 | #x = 5 | |||
decrement | x = --y | y = 4 | x = 4 | |
y = 4 | x = 5 |
Assignment operator
The assignment operator is used to assign values to JavaScript variables. Given x=10 and y=5, the following table explains the assignment operators:Example | Instance | x Value | |
---|---|---|---|
x = y | x = y | x = 5 | |
x = y | x = x y | #x = 15 | |
x -= y | x = x - y | x = 5 | |
x *= y | x = x * y | x = 50 | |
x /= y | x = x / y | x = 2 | |
x %= y | x = x % y | x = 0 |
operator, = operator can be used to concatenate strings.
Given text1 = "Good ", text2 = "Morning", and text3 = "", the following table explains the use of string operators:
Example | text1 | #text2 | text3 | |
---|---|---|---|---|
text3 = text1 text2 | "Good " | "Morning" | "Good Morning" | |
text1 = text2 | "Good Morning" | "Morning" | "" |
Comparison operators are used to judge logical statements to determine whether two given values or variables are equal.
Given x=5, the following table shows the use of comparison operators:
Description | Comparison | The result | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
is equal to | x == 8 | false | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
true | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The value and type are equal (constantly equal to ) | x === "5" | false | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
true | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
is not equal to | x != 8 | true | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The value and type are not equal (not equal) | x !== "5" | true | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
false | ##> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
x > 8 | false | < | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
x < 8 | true | ##> = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
x>= 8 | false | <= | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
x <= 8 | true | Conditional operator The conditional operator is used for assignment operations based on conditions. Given x=6 and y=3, the following table demonstrates the operation of the conditional operator:
Logical operator Logical operators are used to determine the logical relationship between variables or values. Given x=6 and y=3, the following example demonstrates the use of logical operators:
##Bitwise operator Bit operators work on 32-bit numbers. Any numeric operations will be converted to 32 bits. The result is converted to a JavaScript number.
The above is the detailed content of What are the javascript operators?. For more information, please follow other related articles on the PHP Chinese website!
Related labels:
source:php.cn
Previous article:What are the three methods of defining a class in javascript
Next article:How to remove remainder in javascript
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Related Topics
More>
|