How to understand symbol in js
This article mainly introduces "how to understand symbol in js". In daily operation, I believe many people have doubts about how to understand symbol in js. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to understand symbol in js"! Next, please follow the editor to study!
1. The symbol value represents a unique identifier, and you can use Symbol () to create this type of value.
2. Symbol guarantee is unique. Even if we create many Symbol with the same description, their values are different.
Example
Class MyPrime {static [Symbol.hasInstance] (obj) {let element = Number (obj) for (let start = 2; start < element; start++) {if (element% start = 0) {return false; break;}} return true }} console.log (5 instanceof MyPrime); / / true console.log (10 instanceof MyPrime); / / false at this point, the study on "how to understand symbol in js" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!