JavaScript Learning Experience 04

Source: Internet
Author: User
Tags bitwise operators object object

    • 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;
    • NaNis 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
    • undefinedand null strictly equal to oneself;
    • Andnull == 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
    1. Change the priority level;
    2. After the function name is placed, call this function.
      In parentheses, you can only place an expression

JavaScript Learning Experience 04

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.