JavaScript basic Concepts (Operators)

Source: Internet
Author: User
Tags bitwise bitwise operators

Unary operator

The unary operator, when processing all non-numeric values, translates the value through number () to a numeric value.

Bitwise operators

      1. Negative numbers are stored in the form of twos complement on the computer, and the complement is equal to the original code's inverse code plus 1,ecmascript when you output a negative number as a binary string, we see just the binary code with the negative absolute value preceded by a symbol (instead of the output 32-bit binary) such as:
        var num = -18;alert (num.tostring (2));  "-10010"

          

      2. When you apply a bitwise operator to a special Nan and infinity value, both values are treated as a limit of.
      3. When a signed right shift (>>) operation is performed, the left side fills the empty space with the value of the sign bit and fills the empty space with an unsigned Right shift (>>>) operation.

Boolean operator

Logical Non-

When you perform a logical non-operation on a value of a non-Boolean type, a Boolean () is used to convert the value to a Boolean type.

Logic and

      1. is a short-circuit operation and does not necessarily return a Boolean type.
      2. Returns the second operand if the first operand can be converted to true with a Boolean () function.
      3. If the first operand is false,null,nan,undefined, returns the first operand.

Logical OR

      1. The principle is similar to logic.
      2. We can use the following example to avoid assigning null or undefined values to variables, such as:
var myObject = Preferredobject | | Backupobject

If the first variable exists, it gives precedence to the first variable of MyObject, or the second variable

Multiply sex operator

Note: If an operator that participates in multiplicative calculations is not a numeric value, the background will first use the number () transformation function to convert it to a numeric value.

Multiplication

      1. If one of the operands is Nan, the result is Nan;
      2. If the infinity is multiplied by 0, the result is Nan;
      3. If the Infinity is multiplied by a value other than 0, the result is Infinity or-infinity;
      4. If infinity is multiplied with infinity, the result is infinity.

Division

      1. If one of the operands is Nan, the result is Nan;
      2. If the infinity is infinity, the result is Nan;
      3. If 0 is removed by 0, then the result is Nan;
      4. If a non-zero finite number is removed by 0, the result is Infinity or-infinity;
      5. If Infinity is removed by any non-0 value, the result is Infinity or-infinity.

Die-finding

      1. If the divisor is an infinity value and the divisor is a finite large value, the result is Nan;
      2. If the divisor is a finite large number and the divisor is zero, the result is Nan;
      3. If the infinity is infinity, the result is Nan;
      4. If the divisor is a finite number and the divisor is an infinite number, the result is a divisor;
      5. If the divisor is 0, the result is 0.

Additive operator

Addition

If one of the operands is a string, the other operand is converted to a string using the string () transformation function, and then the two strings are stitched together;

Subtraction

If the operand is a non-numeric value, the background call to the number () transformation function first converts it to a numeric value in the operation.

Relational operators

    1. If the two operands are numeric, a numeric comparison is performed;
    2. If the two operands are all strings, the character encoding values corresponding to the two strings are compared;
    3. If an operand is a numeric value, the background will use the number () function to convert it to a numeric value and then compare it.
    4. If an operand is an object, call the object's valueof () method, compare it with the resulting result, and if the object does not have a valueof method, call the ToString () method and compare it with the resulting result.
    5. Nan < 3 and Nan >= 3 return False when Nan is the operand.

Equality operators

Note: Equality and inequality---first conversion and then comparison, congruent and non-congruent---only compare and not convert

Equality and inequality

      1. null and undefined are equal;
      2. If only one operand is a numeric value, the other operand is converted to a number and then compared;
      3. If the two operands are objects, then the comparison is not the same object. The equality operator returns TRUE if all two operands point to the same object.

Conditional operator

As follows: Error this variable is undefined, but does not throw an error.

ABC = true? 12:error

JavaScript Basic concepts (operators)

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.