- Any value (including the Nan itself) is compared to Nan and returns false:
1 > NaN // false1 <= NaN // false‘1’ > NaN // false‘1’ <= NaN // falseNaN > NaN // falseNaN <= NaN // false
- When the array is compared with something else, it becomes a string and a person.
- When a non-array object is compared to something else, it becomes the string directly:
‘[object Object]’
- If two values are not of the same type, the strict equality operator
===
returns directly false
, whereas the equality operator ==
converts them to the same type, and then compares them with the strict equality operator;
NaN
is not equal to any value (including itself). Also, positive 0 equals minus 0:
NaN === NaN // false+0 === -0 // true
- When comparing data for two composite types (objects, arrays, functions), instead of comparing their values for equality, compare whether they point to the same address:
{} === {} // false[] === [] // false(function () {} === function () {}) // false
undefined
and null
strictly equal to oneself;
- And
null == undefined // true
- Two variables that only declare unassigned are equal:
var v1;var v2;v1 === v2 // true
- Bitwise operators only work on integers, and if an operator is not an integer, it is automatically converted to an integer and then executed;
- Although inside JavaScript, values are stored as 64-bit floating-point numbers, but when you do bit operations, they are evaluated as 32-bit signed integers, and the return value is also a 32-bit signed integer:
function toInt32(x) {//将任意数值转化为32位整数 return x | 0;}
- The binary or operation of a decimal with 0 is equivalent to removing the fractional part of the number, that is, taking the integer digits;
- A number is added to its own inverse value, equal to-1:
~ 3 // -4~ -3 // 2
- For an integer two consecutive binary no operations, get it itself;
- A fractional two consecutive binary no operation, can achieve the rounding effect (compared or operation, faster);
- An XOR operation can also be used to take an integer:
12.9 ^ 0 // 12
- If you move the 0-bit to the left, it is equivalent to converting the value to a 32-bit integer, which is equivalent to rounding and valid for positive and negative numbers;
- Use the following methods to view the stored form of a negative integer inside the computer!
-1 >>> 0 // 4294967295
Binary switches
|
manufacturing masks with operations:
var mask = FLAG_A | FLAG_B | FLAG_D;// 0001 | 0010 | 1000 => 1011
- Used
&
to check whether the corresponding switch is turned on;
void operation
Click the link to submit the form, but do not jump to the page.
<a href=“javascript: void(document.form.submit())”> 提交</a>
Comma operator
The comma operator is used to evaluate two expressions, perform the operation before the comma, and then return the value after the comma.
var value = (console.log(‘Hi!’), true);// Hi!value // true
The function of parentheses
- Change the priority level;
- After the function name is placed, call this function.
In parentheses, you can only place an expression
JavaScript Learning Experience 04