operator _ bitwise operators, other operators, assignment operators, ternary operators, operator precedence

Source: Internet
Author: User
Tags bitwise operators

Six Bitwise operators
PS: In general applications, we basically use an operator that is not in place. Although, it is based on the underlying, performance and speed will be very good, but because the lower level, the use of a lot of difficulty. So, we treat it as a choice to learn. There are seven bitwise operators, namely, bit non-not (~), Bit and and (&), bit or OR (|), bitwise XOR (^), left Shift (<<), signed right Shift (>>), unsigned Right shift (>>>).
var box = ~25; -26
var box = & 3; 1
var box = 25 | 3; 27
var box = << 3; 200
var box = >> 2; 6
var box = >>> 2; 6

Seven Assignment operators
The assignment operator is denoted by the equals sign (=), which assigns the right value to the left variable.
var box = 100; Assign 100 to the box variable
The compound assignment operator is represented by a x=, and X represents an arithmetic operator and a bitwise operator.
var box = 100;
box = Box +100; 200, add 100 to yourself
This situation can be rewritten as:
var box = 100;
box + = 100; 200,+= instead of box+100
In addition to this + = Plus/assignment operator, there are several others as follows:
1. Multiply/assign (*=)
2. Addition/Assignment (/=)
3. Mold/Fu (%=)
4. Add/assign (+ =)
5. Subtract/assign (-=)
6. Shift Left/assign (<<=)
7. Signed Right Shift/Assignment (>>=)
8. No sign with shift/Assignment (>>>=)

Eight Other operators
1. String operators
The string operator has only one, that is: "+". Its purpose is to add two strings. Rule: At least one operand is a string.
var box = ' 100 ' + ' 100 '; 100100
var box = ' 100 ' + 100; 100100
var box = 100 + 100; 200
2. Comma operator
The comma operator can perform multiple operations in a single statement.
var box = +, age = 178, height = +; Multiple variable declarations
var box = (1,2,3,4,5); 5, variable declaration, assigning the last value to a variable, not commonly used
var box = [1,2,3,4,5]; [1,2,3,4,5], the literal declaration of an array
var box = {//[object Object], object literal declaration
1:2,
3:4,
5:6
};
3. Ternary conditional operators
The ternary conditional operator is actually the shorthand form of the IF statement that will be learned later.
var box = 5 > 4? ' Yes ': ' wrong '; Yes, 5>4 returns true to assign ' pair ' to box, and vice versa.
Equivalent:
var box = '; Initialize variables
if (5 > 4) {//Judgment expression return value
box = ' yes '; Assign value
} else {
box = ' wrong '; Assign value
}


Nine Operator Precedence
In a general operation, we do not have to take into account the precedence of operators, because we can solve this problem by using parentheses. Like what:
var box = 5-4 * 8; -27
var box = (5-4) * 8; 8
However, if you do not use parentheses to enforce precedence, we must follow the following order:

1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTMLxmlns= "http://www.w3.org/1999/xhtml">3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312" />5 <title>Operator</title>6 <Scripttype= "Text/javascript">7 /*8 var box = 100;//Assign 100 to the box variable9 alert (box);Ten  One var box = +; A box = box +100;//200, self-added - alert (box); -  the var box = +; - box + + +; - alert (box);//200,+= instead of box+100 - */ +  - /* + var box = ' + ' + '; A alert (box);//100100 at     - var box = ' + ' +; - alert (box);//100100 -      - var box = + +; - alert (box);//200 in  -  to var box = +, age =, height = 178;//multiple variable declarations + alert (box); - alert (age); the alert (height); *      $ var box = (1,2,3,4,5);Panax Notoginseng alert (box);//5, variable declaration, assigning the last value to a variable, not commonly used -      the var box = [1,2,3,4,5]; + alert (box);//[1,2,3,4,5], the literal declaration of an array A      the var box = {//[object Object], object literal declaration + 1:2, - 3:4, $ 5:6 $ }; - alert (box); - */ the /* - var box = 5 > 4? ' Yes ': ' wrong ';Wuyi alert (box);//Yes, 5>4 returns true to assign ' pair ' to box, and vice versa.  the      - var box = ";//Initialize variable Wu if (5 > 4) { - box = ' yes '; About } else { $ box = ' wrong '; - } - alert (box); - */ A /* + var box = 5-4 * 8; the alert (box);//-27 -      $ var box = (5-4) * 8; the alert (box);//8 the */ the </Script> the </Head> -  in <Body> the Welcome to the world of JavaScript the </Body> About </HTML>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.