[Effective JavaScript notes] chapter I: Getting used to JavaScript summary

Source: Internet
Author: User

Here to tidy up, each of the corresponding tips

1th: Understand the use of the JS version
    1. Determine the version of JS supported by the application (browser is also an application OH)
    2. Make sure that the JS feature you use is supported by your application (or it won't work if you write it)
    3. Always write and test code in strict mode (for future programming)
    4. Pay attention to the strict patterns of different claims when merging code (or the second solution, worry)
2nd: Understanding the floating-point number of JavaScript
    1. JS is a double-precision floating-point number.
    2. JS integers are just a subset of the double-precision floating-point numbers, not a single type
    3. Bitwise arithmetic treats a number as a 32-bit signed integer
    4. When the accuracy problem of impatient point arithmetic
3rd: Beware of implicit casts
    1. Type errors are hidden by an implicit cast
    2. Whether the operator + is an addition or a string join operation depends on the parameter type.
    3. ValueOf cast to a number, ToString casts to a string
    4. An object that implements the ValueOf method should implement a ToString method that returns a string representation of the return value of the valueof method
    5. Tests whether a value is undefined, should use typeof or directly compared to undefined, should not use the truth operation
4th: The original type is better than the enclosing object
    1. As an equality comparison, the encapsulated object of the original type behaves differently from its original value. The original value must be equal to the original value, encapsulating the object not equal to the same value as the encapsulated object.   "MM" = = "MM"; New string ("MM")! = new String ("MM")
    2. Getting and setting properties of the original type implicitly creates an encapsulated object. A new encapsulated object is created each time, so the value set is not preserved.
5th: Avoid using the = = Operator for mixed types
    1. When the parameter type is not the same, the = = operator applies a set of hard-to-understand implicit casting rules.
    2. with the = = = operator, you can avoid remembering those casting rules to make your code clearer.
    3. When comparing values of different types, it is best to explicitly cast them to make the program behave more clearly.
6th: Understanding the limitations of semicolon insertion
    1. Automatically insert semicolons only before the "}" tag, at the end of a line, and at the end of a program
    2. Inserts a semicolon only when the immediately preceding token cannot be parsed
    3. You must never omit a semicolon before a statement that starts with (, [, + 、-、/character
    4. When a script file is connected, a defensive semicolon is added at the beginning of the script
    5. Must not be wrapped before return, throw, break, continue, + +,--parameters
    6. Semicolons cannot be inserted automatically as a delimiter for a for loop's head or an empty statement
7th: Sequence of code elements with a 16-bit view string
    1. The JS string is made up of 16-bit code units, not a Unicode code point.
    2. JS uses two code units to represent 216 and more of the Unicode code points. These two code units are called proxy pairs.
    3. The proxy pair threw away the count of string elements, and the Length,charat,charcodeat method and the regular expression pattern were affected.
    4. Use a third-party library to write string operations that recognize code points.
    5. Whenever you use a library with a string operation, you need to look at the library document as if it were the entire range of code points.

[Effective JavaScript notes] chapter I: Getting used to JavaScript summary

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.