Avoid relying on null The difference between and undefined. This often leads to code vulnerability . Use non mandatory equality when checking the equality of any one of them （==）null. Avoid using both to represent different types of “ No value ” situation , for example “unknown field” And “no value for today”.
Be careful not to use true and false check zero . If there are numbers , It usually needs to be treated in the same way as any other number - Unlike other false values .
avoid setTimeout() Or something like vulnerability or incomprehension . Through careful selection （ Usually by trial and error ） Run a piece of code after a time delay , It may happen, it may be difficult to achieve / The plan of repair . The reason why this method works （ At least for some time ） Little known to the author , And lead to fragile and unpredictable behavior - Especially when the delay is nonzero .
Pay attention to instance methods that mutate in situations that may not be expected . These include Array On the spot reverse(), And many Moment.js Method （ Seriously consider alternatives , Such as date-fns or Luxon）.
Array sort() Convert elements to strings , And sort them alphabetically by default . For anything but strings , It's not likely to be what you want - The function of comparator must be given .
character string replace() Replace the first match only when using a string as a pattern . Global substitution requires regular expressions .
Try to avoid duck Type checking . If the duck To change , They break easily , And it doesn't convey the intention very well .
Avoid layout bumps caused by cross read and write . Group read and write as much as possible Lead to layout / The properties of rearrangement .
Avoid overwork in response to user input . This includes calculation , Screen updates and requests to the server . Consider removing jitters or limiting keyboard input and certain types of mouse events .
Avoid using outdated technology . The progress of language continues to bring about the renewal of many traditional technologies , A better alternative . Use them . Examples include async / await And template string .