In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about what types of javascript operators can be divided into. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Javascript operators can be divided into: 1, arithmetic operators, used to perform common mathematical operations; 2, assignment operators, used to assign values to variables; 3, string operators; 4, self-increasing and self-subtracting operators; 5, comparison operators; 6, logical operators; 7, ternary operators; 8, bit operators.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Arithmetic operator
Arithmetic operators are used to perform common mathematical operations, such as addition, subtraction, multiplication, division, and so on. The following table lists the arithmetic operators supported in JavaScript:
Operator description example + addition operator x + y for sum-subtraction operator x-y for calculation x minus y * multiplication operator x * y for product / division operator x / y for calculation x divided by y quotient% modulus (remainder) operator x% y represents the remainder of calculation x divided by y
The sample code is as follows:
Copy plain text copy var x = 10, y = 4 console.log ("x + y =", x + y); / / output: X + y = 14console.log ("x-y =", x-y); / / output: X-y = 6console.log ("x * y =", x * y); / / output: X * y = 40console.log ("x / y =", x / y) / output: X / y = 2.5console.log ("x% y =", x% y); / / output: X% y = 2var x = 10, y = 4 console.log ("x + y =", x + y); / / output: X + y = 14console.log ("x-y =", x-y); / / output: X-y = 6console.log ("x * y =", x * y) / output: X * y = 40console.log ("x / y =", x / y); / / output: X / y = 2.5console.log ("x% y =", x% y); / / output: X% y = 2
In the above code, the content in the double quotation marks is a string, so the operators in it are output as is and do not participate in the operation.
Assignment operator
Assignment operators are used to assign values to variables, and the following table lists the assignment operators supported in JavaScript:
Operator description example = the simplest assignment operator, assigning the value on the right side of the operator to the variable x = 10 on the left side of the operator means that the variable x = 10 is assigned to do the addition operation first, and then assign the result to the variable x + = y on the left side of the operator equal to x = x + y color = to do subtraction first, and then assign the result to the variable x-= y on the left side of the operator equal to x = x-y = first multiply Then the result is assigned to the variable x * = y on the left side of the operator is equivalent to x = x * y = first divide, and then the result is assigned to the variable x / = y on the left side of the operator is equal to x = x / y% =. Then assign the result to the variable x% = y on the left side of the operator is equal to x = x% y
The sample code is as follows:
Copy plain text copy var x = 10 x + = 20 position console.log (x); / / output: 30var x = 12, y = 7 x-= y position console.log (x); / / output: 5x = 5x * = 25X console.log (x); / / output: 125x = 50X / = 10 position console.log (x); / / output: 5x = 100x x% = 15position console.log (x) / / output: 10var x = 10 × x + = 20 position console.log (x); / / output: 30var x = 12, y = 7 × x-= y position console.log (x); / / output: 5x = 5x * = 25 × console.log (x); / / output: 125x = 50 X / = 10 position console.log (x); / / output: 5x = 100 X% = 15scape console.log (x); / output: 10
String operator
In addition to mathematical operations, the + and + = operators in JavaScript can also be used to concatenate strings, where:
The + operator means to concatenate the strings on the left and right sides of the operator.
The + = operator means that the string is concatenated and then the result is assigned to the variable to the left of the operator.
The sample code is as follows:
Copy plain text copy var x = "Hello"; var y = "World!"; var z = x + yposition console.log (z); / / output: Hello Worldconsolex + = yposition console.log (x); / / output: Hello Worldconsolvar x = "Hello"; var y = "World!"; var z = x + yscape console.log (z); / / output: Hello Worldconsole.log (x); / output: Hello World!
Self-increasing and self-decreasing operators
The self-increment and self-subtraction operators are used to perform self-increment (+ 1) and self-subtraction (- 1) operations on the values of variables. The following table lists the self-increment and self-subtraction operators supported in JavaScript:
The operator name affects + + x the self-increasing operator adds x to 1, then returns the value of x, and then the self-increasing operator returns the value of x, then subtracts x by 1, then subtracts x by 1, and then returns the value of x by the x-self-subtraction operator, and then subtracts x by 1.
The sample code is as follows:
Copy plain text copy var xbot x = 10 console.log (+ + x); / / output: 11console.log (x); / / output: 11x = 10 console.log (x +); / / output: 10console.log (x); / / output: 11x = 10 position console.log (--x); / / output: 9console.log (x); / / output: 9x = 10 position console.log (xrel -) / / output: 10console.log (x); / / output: 9var x = 10 + console.log (+ + x); / / output: 11console.log (x); / / output: 11x = 10 console.log (x +); / / output: 10console.log (x); / / output: 11x = 10 console.log (--x); / / output: 9console.log (x); / / output: 9x = 10 Console.log (xMel -); / / output: 10console.log (x); / / output: 9
Comparison operator
The comparison operator is used to compare the expressions on the left and right sides of the operator. The result of the comparison operator is a Boolean value, and there are only two results, either true or false. The comparison operators supported in JavaScript are listed in the following table:
Operator name example = = equal to x = = y means true if x is equal to y, true = = congruent x = y means true if x is equal to y and x and y are of the same type, then true! = unequal x! = y means true if x is not equal to y, then true! = incomplete equal x! = y means if x is not equal to y, or if x and y have different types, then true is greater than x > y means that if x is greater than y True > = greater than or equal to x > = y means that if x is greater than or equal to y, it is true y) / / output: falseconsole.log (x = y); / / output: false
Logical operator
Logical operators are usually used to combine multiple expressions. The result of a logical operator is a Boolean, and there can only be two results, either true or false. The logical operators supported in JavaScript are listed in the following table:
Example of operator name & & logical and x & & y means true if both x and y are true | | logical or x | | y means true if either x or y is true! Logic is not! X means that if x is not true, it is true.
The sample code is as follows:
Copy plain text copy var year = 2021 / leap year is divisible by 400 or 4, but not divisible by 100. if ((year% 400 = = 0) | | ((year% 100! = 0) & & (year% 4 = = 0)) {console.log (year + "year is a leap year.") ;} else {console.log (year + "the year is an ordinary year.") ;} var year = 2021 / leap year is divisible by 400or 4, but not divisible by 100. if ((year% 400 = = 0) | ((year% 100100! = 0) & & (year% 4 = = 0)) {console.log (year + "year is a leap year.") ;} else {console.log (year + "the year is an ordinary year.") ;}
Ternary operator
The ternary operator (also known as the conditional operator) consists of a question mark and a colon and has the following syntax format:
Conditional expression? Expression 1: expression 2
If the result of the conditional expression is true (true), the code in expression 1 is executed, otherwise the code in expression 2 is executed.
The sample code is as follows:
Copy plain text, copy var x = 11, y = 20th x > y? Console.log ("x greater than y"): console.log ("x less than y"); / / output: X less than yvar x = 11, y = 20 x > y? Console.log ("x greater than y"): console.log ("x less than y"); / / output: X less than y
Bit operator
Bit operators are used to operate on binary bits, and the bit operators supported in JavaScript are shown in the following table:
Operator description example & bitwise and: if the corresponding binary bit is 1, the binary bit is 15-1 equal to 0101-0001, the result is 0001, and the decimal result is 1 | bitwise OR: if one of the corresponding binary bits is 1, then the binary bit is 15 | 1 equals 0101 | 0001 results are 0101, and the decimal result is 5 ^ bitwise XOR: if only one of the corresponding binary bits is 1 Then the binary bit is 15 ^ 1 equal to 0101 ^ 0001, the result is 0100, and the decimal result is 4 ~ bitwise non: reversing all binary bits, that is, converting 1 to 0, converting 0 to 1, converting 0 to 0101, the result is 1010, the decimal result is-6 1 equals 0101 > > 1, the result is 0010, the decimal result is 2 > move zero to the right (unsigned right): move all binary bits to the right by the specified number of digits And on the far left, complement 05 > > 1 equals 0101 > 1, the result is 0010, and the decimal result is 2.
The sample code is as follows:
Copy plain text copy var a = 5 & 1, b = 5 | 1, c = 5 ^ 1, d = ~ 5, e = 5 > 1, g = 5 > > 1 console.log (a); / / output: 1console.log (b); / / output: 5console.log (c); / / output: 4console.log (d); / / output:-6console.log (e); / / output: console.log (f) / / output: 2console.log (g); / / output: 2var a = 5 & 1, b = 5 | 1, c = 5 ^ 1, d = ~ 5, e = 5 > 1, g = 5 > 14console.log console.log (a); / / output: 1console.log (b); / / output: 5console.log (c); / / output: 4console.log (d); / / output:-console.log (e) / / output: 10console.log (f); / / output: 2console.log (g); / / output: 2 Thank you for reading! This is the end of this article on "which categories of javascript operators can be divided into". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.