Some error-prone records encountered in daily work and seen in articles
1: if the codemay
A variable name is not declared
- Use typeof name === ‘undefiend’ // so that we can judge whether there is a defiend or not
- Instead of if(name) // an error is reported because name is not declared
2: setTimeout returns a timmerId variable
Clear timer, clearTimeout(timmerId); Clearing the timer prevents the timer task from executing, not sets the timmerId to NULL
3: negative margin
margin-left: -10px; To close the distance to the left means to move yourself 10px to the left. It’s used in the Grail layout
4: Position: absolute of pseudo elements
If its own elements are position: relative, absolute, or fixed, it is positioned relative to its own position
5: Everything in JavaScript is: raw value or object
6: Only 6 false values in JavaScript:
- undefined
- null
- NaN
- 0
- ” (empty string)
- false
Note: Function constructors such as new Number and new Boolean are true values.
7: when the object is used as the key of object type
It’s automatically converted to stringification. It becomes stringification
[Object object]
Copy the code
Example:
const a = {}; const b = { key: "b" }; const c = { key: "c" }; a[b] = 123; a[c] = 456; console.log(a[b]); / / 456Copy the code
8: If an object has two keys with the same name, the previous key will be replaced. It will still be in the first position, but it will have the last specified value.
const obj = { a: "one", b: "two", a: "three" };
console.log(obj);
A: { a: "one", b: "two" }
B: { b: "two", a: "three" }
C: { a: "three", b: "two" }
D: SyntaxError
Copy the code
Answer: C
9:{age: 18} == {age: 18} is not equal
Because both sides of the equal sign create two reference addresses in the stack area, the two reference addresses are not equal