Basic JavaScript knowledge is forgotten

Source: Internet
Author: User
Tags bitwise operators

5% 10 = 5
X = "5" + "5 ";
X = "5" + 5;
Document. write (x); (the result is: 55)

Undefined is the value of an uninitialized variable. It has no reference value, which is beyond undefined.
Var anyway; anyway was specified to have a null value.

One-dimensional operation OPERATOR: delete (except the reference to the object and method defined by the developer, the original ECMAScript method cannot be used)
The void operator returns undefined for any value.

The functions without return values actually return undefined.

The one-dimensional addition essentially has no effect on numbers.
The method for calculating a string using a one-dimensional addition is similar to parseInt ().
Area differences: only the one-dollar addition can be used to perform linear regression on octal and hexadecimal strings (such as OxB and 010 ).

One-dimensional subtraction calculates the string, converts the string to an approximate number, and then evaluates the negative value.

ECMAScript integers are of two types: signed integers and unsigned integers.

0 indicates a positive number, and 1 indicates a negative number.
Positive numbers are stored in real binary format.
Negative numbers are also stored as binary code, which uses binary complement.
Calculate the binary complement code of a number: inverse addition of a pair Value

When processing signed integers, developers cannot access 31 characters.

Var iNum =-18;
Alert (iNum. toString (2 ));
The output is "-10010", which is a non-binary complement code. In order to avoid the need for 31 bits

The value range of an unsigned integer is 0 to 4294967295.
After an unsigned integer is converted to a string, only the valid bits are returned.

Bit operation NOT (~) , Bitwise operation AND, bitwise operation OR (|), unsigned right shift operation (>>>)
Left shift operation (<) Note: The left shift operation retains the symbol bit of the number.
Bit operations (XOR) are represented by symbols (^ ).
1 is returned only when one digit is saved as 1.
All integers are stored as signed integers by default.
Only the bitwise operators of ECMAScript can create unsigned integers.

Var iNum1 = 25; // 25 equals 00000000000000000000000000011001
Var iNum2 = ~ INum1; // convert to 11111111111111111111111111100110
Alert (iNum2); // output "-26"

<! -- // --> Deal with old browsers
/**/Multi-line comment

The action of the logical NOT operator is as follows:
* If the number of operations is 0, true is returned.
* If the number of operations is any number other than 0, false is returned.
* If the number of operations is null, true is returned.
* If the number of operations is NaN, true is returned.
* If the number of operations is undefined, an error occurs.
!! SBlue, the first NOT operator returns a Boolean value. The second NOT evaluates the negative value of this Boolean value.

The logical AND operation does not necessarily return a Boolean value:
* If one operation is an object and the other is a Boolean value, this object is returned.
* If both operations are objects, the second object is returned.
* If the number of operations is null, null is returned.
* If the number of operations is NaN, NaN is returned.

Similar to the logical AND operator, if the number of operations is not a Boolean value, the logical OR operation does not necessarily return a Boolean value:
* If one operation is an object and the other is a Boolean value, this object is returned.
* If both operations are objects, the first object is returned.
* If the number of operations is null, null is returned.
* If the number of operations is NaN, NaN is returned.

Multiplication operator (*)
* If the result is too large or too small, the generated result is Infinity or-Infinity.
* If the number of operations is NaN, the result is NaN.
* If Infinity is multiplied by 0, the result is NaN.
* If Infinity is multiplied by any number other than 0, the result is Infinity or-Infinity.
* If Infinity is multiplied by Infinity, the result is Infinity.

Division operator (/)
* If the number of operations is NaN, the result is NaN.
* Infinity is divided by Infinity, and the result is NaN.
* Infinity is divided by any number and the result is Infinity.
* 0 returns NaN in addition to any non-infinite number.
* Infinity is divided by any number other than 0, and the result is Infinity or-Infinity.

Modulo operator (%)
* If the divisor is Infinity or the divisor is 0, the result is NaN.
* Infinity is divided by Infinity, and the result is NaN.
* If the divisor is an infinite number, the result is the divisor.
* If the divisor is 0, the result is 0.

Var bResult = "25" <"3 ";
The two operations are strings, so they compare their character code. The character code of "2" is 50, and the character code of "3" is 51.
Var bResult = "25" <3;
The string "25" is converted to the number 25 and then compared with the number 3.
Returns false for any Relational operators that contain NaN ("a" <15, a minus returns NaN with parseInt)

Equal signs and non-equal signs are used to process the original values (numeric values are written before the line), and full and non-full signs are used to process objects.
The rules for executing type conversion are as follows:
* If the number of operations is a Boolean value, convert it to a numeric value before checking equality. Convert false to 0, true to 1 (true! = 2)
* If one operation is a string and the other is a number, convert the string to a number before checking for equality. ("5" = 5)
* If one operation is an object and the other is a string, convert the object to a string before checking equality.
* If one operation is an object and the other is a number, convert the object to a number before checking for equality.
Observe the following rules:
* The null and undefined values are equal.
* When equality is checked, null and undefined cannot be converted into other values. (Undefined! = 0, null! = 0)
* If the number of operations is NaN, the equal sign will return false, and the non-equal sign will return true. (NaN! = NaN)
* If both arithmetic operations are objects, the referenced values are compared. If the number of two operations points to the same object, the equal sign returns true; otherwise, the number of two operations varies.

Full and non-full signs (type conversion is not performed)

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.