17.symbol.html 774 B

1234567891011121314151617181920212223242526272829
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. /**
  11. * Symbol
  12. * 基本数据类型:
  13. * number null undefined boolean string
  14. * symbol(新增的):
  15. * 1.独一无二的值 避免命名冲突 解决命名问题
  16. * 2.symbol声明的数据类型与其他数据类型不允许做运算
  17. * 3.symbol 不能使用for...in循环
  18. *
  19. */
  20. let s1 = Symbol();
  21. console.log(s1);
  22. console.log(typeof s1);
  23. let s2 = Symbol("张三");
  24. let s3 = Symbol("张三");
  25. console.log(s2===s3); // false
  26. </script>
  27. </body>
  28. </html>