Home > headlines > Highly recommended: 20 ES6 tips worth collecting

Highly recommended: 20 ES6 tips worth collecting

Release: 2022-04-19 16:23:48
forward
3738 people have browsed it

This article organizes and shares ES6 tips, and compiled 20 frequently used ES6 code blocks for everyone. I hope you like it!

1. Disrupt the order of the array

Highly recommended: 20 ES6 tips worth collecting

##[Related recommendations:

javascript learning tutorial

2. Remove all characters except numbers

Highly recommended: 20 ES6 tips worth collecting

3. Reverse a string or word

Highly recommended: 20 ES6 tips worth collecting

4. Convert decimal to binary or hexadecimal

Highly recommended: 20 ES6 tips worth collecting

5. Merge multiple objects

Highly recommended: 20 ES6 tips worth collecting

6. ===<span style="font-size: 18px;"></span> and ==<span style="font-size: 18px;"></span># The difference between

Highly recommended: 20 ES6 tips worth collecting

#7. Destructuring assignment

Highly recommended: 20 ES6 tips worth collecting

8. Exchange the value of the variable

Highly recommended: 20 ES6 tips worth collecting

9-1. Judgment Palindrome string

9-Highly recommended: 20 ES6 tips worth collecting

Palindrome string: A string that is the same when written frontward or backward

9-2 Determine whether two strings are arranged with each other

9-Highly recommended: 20 ES6 tips worth collecting

Determine two characters Whether strings are permuted: Given two strings, whether one is a permutation of the other

10. Optional chaining operator

Highly recommended: 20 ES6 tips worth collecting

MDN:
Optional chain

operator ( ?. ) allows reading properties located deep in the connection object chain value without having to explicitly verify that each reference in the chain is valid. The function of the ?. operator is similar to the . chain operator. The difference is that when the reference is null (nullish) (null or undefined) will not cause an error, the short-circuit return value of this expression is undefined. When used with a function call, if the given function does not exist, returns undefined

For example:
if (res && res.data && res.data.success) {   
   //code} 
复制代码
Copy after login

is equivalent to:

if (res?.data?.success) {  // code}复制代码
Copy after login

11. Ternary operator

1Highly recommended: 20 ES6 tips worth collecting

12. Randomly select a value from the array

1Highly recommended: 20 ES6 tips worth collecting

13. Freezing Objects

1Highly recommended: 20 ES6 tips worth collecting

14. Delete duplicate elements from the array

1Highly recommended: 20 ES6 tips worth collecting

15. Keep the specified decimal places

1Highly recommended: 20 ES6 tips worth collecting

##16. Clear the array

17. Convert from <span style="font-size: 18px;">RGB</span> to <span style="font-size: 18px;">HEX</span>

1Highly recommended: 20 ES6 tips worth collecting

18. Get the maximum and minimum values ​​from the array

1Highly recommended: 20 ES6 tips worth collecting

19. Null value coalescing operator

Highly recommended: 20 ES6 tips worth collecting

##MDN:

Null value coalescing operator??) is a logical operator. When the operand on the left is null or undefined, it returns the operand on the right, otherwise it returns the left Operands.

20. Filter the values ​​in the array that are false<span style="font-size: 18px;"></span>

Highly recommended: 20 ES6 tips worth collecting

Source code

https://github.com/xieyezi/vuepress-blog/ blob/master/docs/front-end/ES6-20 frequently used techniques.md

Above, coding and drawing is very hard, I hope you don’t be stingy with your likes and likes. This is my biggest motivation to continue updating!

[Related video tutorial recommendations:

web front-end]

Related labels:
source:weixin
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