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

Source: Internet
Author: User
Tags bitwise bitwise operators

One, bitwise operators
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, and that is because the lower level, the use of the difficulty is also very large, the underlying operation is converted to binary operation.

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 // -26 var // 1 var //  - var //  $ var // 6 var // 6



Second, assignment operator
The assignment operator is denoted by the equals sign (=), which assigns the right value to the left variable.

var // 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 =200, self-added

This situation can be rewritten as:

var box =+//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 (>>>=)

Third, other operators
1. String operator: Only one, that is: "+". Its purpose is to add two strings. Rule: At least one operand is a string.

var // 100100 var // 100100 var //  $


2. Comma operator: You 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< c13>, 5:6 };

Four or three-tuple operator:

  is actually the shorthand form of the IF statement.

var box = 5 > 4? ' Yes ': ' wrong ';        // Yes, 5>4 returns true to assign ' pair ' to box, and vice versa. 

Equivalent:

var // Initialize Variables if (5 > 4)     { // judgment expression return value box = ' yes '; // Assign Value Else  // assignment }




Four, 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 // -27 var // 8  

However, if you do not use parentheses to enforce precedence, we must follow the following order:

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

Related Article

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.