Home > Web Front-end > JS Tutorial > What is the error-prone knowledge about JS?

What is the error-prone knowledge about JS?

零下一度
Release: 2017-07-20 17:20:10
Original
1147 people have browsed it

#What is the error-prone knowledge about JS?

  • The difference between == and ===:

    • ==: Determine the difference between two variables Whether the values ​​are equal.

    • ===: Determine whether the types and values ​​of two variables are equal. When both conditions are met at the same time, the expression is True.

  • The role of break in switch:

    • For example: when case 2 that satisfies the conditions, there is no break below , case 3 will also be executed

    • If the statement after a case does not write break, then the program will execute downwards without exiting;

    •  1 var num = 2; 2 switch(num){ 3     case 1: 4         alert('case 1'); 5         break; 6     case 2: 7         alert('case 2'); 8     case 3: 9         alert('case 3');10         break;11     default:12         alert('default');13         break;14 }
      Copy after login
      View Code
  • ## Array:

    • For example: list1 = new Array(3); 3 represents the length of the array;

    • When using new Array() to define an array, if inside the Array function There is only one number, then this number represents the length of the array, not the elements in the array;

    ##         list2 = new Array(3,2,5,6); The numbers here are elements in the array;

    Data type conversion and NaN:
    • NaN == NaN: What is returned is a false
    • parseInt('123abc') : Returns 123
    • parseInt('abc123') : Returns NaN
    • Number('123abc'): Returns NaN
    • Number('abc123'): Returns NaN
    Decimal operation accuracy problem:
    • In JavaScript, there will always be many decimal places when calculating data with decimals. This is because in JavaScript The calculation of floating point numbers is based on binary system.

The above is the detailed content of What is the error-prone knowledge about JS?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template