You don't know the basic JavaScript details

Source: Internet
Author: User

Syntax section
  1. Type property: The default type is JavaScript, so you do not have to explicitly specify the type as JavaScript

  2. JavaScript does not force a ";" at the end of each statement, and JavaScript automatically adds semicolons, but in some cases it changes the semantics of the program, so it's best to actively add ";"

  3. Two comparison of equality operators

    ' = = ' is equal (value equal), it automatically converts the data type to compare, and many times it gets very weird results.

    ' = = = ' is strictly equal (data type and value are equal), it does not automatically convert data type, if data type is inconsistent, return false, if consistent, then compare

  4. NaN is not equal to all other values, including itself:

    Nan = = = Nan; False

    The only way to judge NaN is through the IsNaN () function

    IsNaN (NaN); True

  5. Floating-point comparison

    Floating-point numbers generate errors during operation because the computer cannot accurately represent infinite loop decimals. To compare two floating-point numbers for equality, you can only calculate the absolute value of their difference to see if they are less than a certain threshold: Math.Abs (1/3-(1-2/3)) < 0.0000001; True

  6. null and undefined

    In most cases, we should all use null, undefined is only useful in judging if the function parameter is passed

  7. For readability of the code, creating an array suggests ' [] ' without using ' new array ';

  8. If a variable is not used by the ' var ' declaration, then the variable is automatically declared as a global variable. A variable declared with VAR is not a global variable, and its scope is limited to the body of the function declared by that variable.

  9. Enable strict mode (force declaration of variables via VAR)

  10. Multi-line strings are expressed in inverted quotation marks

  11. Working with template strings

  12. To get a character at a specified position in a string, use an Array-like subscript operation with the index number starting at 0. The string is immutable, if the

    An index of a string is assigned a value, there is no error, but it does not have any effect

  13. Assigning a new value directly to the length of the array will result in an array size change

  14. If an index is assigned a value, the index is out of range, and the size of the ' array ' changes, but there is no error, and when writing code, it is not recommended to modify the size of ' array ' directly, to ensure that the index does not cross over when accessing the index

  15. The number 30 and the string ' 30 ' are different elements

  16. The starting and ending parameters of slice () include the start index, excluding the end index.

  17. If you do not pass any arguments to slice (), it will intercept all elements from beginning to end. With this, we can easily copy an Array

  18. Empty array continues ' pop ' without error, but returns ' undefined '

  19. The ' concat () ' method does not modify the current ' array ', but instead returns a new ' array ', the ' concat () ' method can receive any element and ' array ', and automatically takes ' array ' apart and then adds it all to the new ' array '

  20. The ' JavaScript ' object property name must be a valid variable name. If the property name contains special characters, it must be enclosed in "".

  21. If we want to detect if ' xiaoming ' has a property, you can use the in operator, but be careful that if ' in ' determines that an attribute exists, this property is not necessarily ' xiaoming ', it may be ' xiaoming ' inherited

  22. To determine whether a property is owned by ' Xiaoming ' itself, and not inherited, you can use the ' hasownproperty () ' method

  23. JavaScript treats ' null ', ' undefined ', ' 0 ', ' NaN ' and empty string ' ' as ' false ', and all other values are considered ' true '

  24. Because ' array ' is also an object, and its index of each element is treated as a property of the object, the ' for ... in ' Loop can directly loop out the index of ' array '

  25. ' For ... in ' Loop because of historical problems, it iterates over the object's property name, and the ' for ... ' loop completely fixes these problems, it only loops the elements of the collection itself

Web Front End/HTML5 Learning Group: 250777811

Function
    1. function if there is no ' return ' statement, the function will return the result after execution, only the result is ' undefined '

    2. Because ' JavaScript ' allows you to pass in any parameter without affecting the call, there is no problem in passing in parameters that are more than the defined parameters, although they are not required internally, and the parameters passed in are less than defined.

    3. The keyword ' arguments ' is similar to ' array ' but it is not an ' array '

    4. Variables that are not defined within any function have global scope. In fact, ' JavaScript ' has a Global object ' window ' by default. The function defined by the variable ' var foo = function () {} ' is actually a global variable.

    5. With ' var = this, ' You can safely define other functions within the method, rather than heap all the statements into a single method. For normal function calls, the ' this ' is usually bound to ' null '.

    6. The only difference between ' apply () ' and ' Call (') '

      -' Apply () ' package the parameters into ' Array ' and then pass in;

      -' Call () ' passes parameters in order.

    7. The prototype of all instances refers to the prototype property of the function

    8. The ' This ' inside the arrow function is the lexical scope (the scope that is determined when writing code or defined, dynamic scope is determined at run time), determined by the context. The arrow function completely fixes the point of ' this ', and ' this ' always points to the lexical scope

Standard Object
    1. If we are using ' number ', ' Boolean ' and ' String ', we do not write ' new ', ' number () ', ' Boolean () ' and ' St ' Ring () ' is used as a normal function to convert any type of data to ' number ', ' Boolean ', and ' string ' type (note not its wrapper type)

    2. Do not use ' new number () ', ' new ' The Boolean () ', ' New String ' () ' creates the wrapper object;

    3. uses ' parseint () ' or ' parsefloat () ' to convert any type to ' number ';

    4. with ' String () ' to convert any type to ' string ', or to invoke the ' toString () ' method of an object directly;

    5. Usually does not have to convert any type to ' Boolean ' because it can be written directly ' if ' (MyVar) {...} ';

    6. ' typeof ' operator can determine ' number ', ' Boolean ', ' string ', ' function ' and ' undefined ';

    7. Judge ' Array ' To use ' Array.isarray ',

    8. To determine ' null ' use ' MyVar = = = NULL ';

    9. To determine if a global variable exists with ' typeof window. MyVar = = = ' undefined '; the

    10. Function internally determines whether a variable exists with ' typeof MyVar = = = ' undefined '.

    11. Does any object have a ' toString () ' method? ' null ' and ' undefined ' are not!

    12. ' Number ' object calls ' toString () ' Report ' SyntaxError '

Web Front End/HTML5 Learning Group: 250777811

Welcome to this public number → "web front-end edu" With the big guy to learn the front end! Welcome message to discuss together with the forwarding

You don't know the basic JavaScript details

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.