Type property: The default type is JavaScript, so you do not have to explicitly specify the type as JavaScript
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 ";"
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
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
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
null and undefined
In most cases, we should all use null, undefined is only useful in judging if the function parameter is passed
For readability of the code, creating an array suggests ' [] ' without using ' new array ';
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.
Enable strict mode (force declaration of variables via VAR)
Multi-line strings are expressed in inverted quotation marks
Working with template strings
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
Assigning a new value directly to the length of the array will result in an array size change
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
The number 30 and the string ' 30 ' are different elements
The starting and ending parameters of slice () include the start index, excluding the end index.
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
Empty array continues ' pop ' without error, but returns ' undefined '
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 '
The ' JavaScript ' object property name must be a valid variable name. If the property name contains special characters, it must be enclosed in "".
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
To determine whether a property is owned by ' Xiaoming ' itself, and not inherited, you can use the ' hasownproperty () ' method
JavaScript treats ' null ', ' undefined ', ' 0 ', ' NaN ' and empty string ' ' as ' false ', and all other values are considered ' true '
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 '
' 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