ES2019 introduces the Symbol.prototype.description property. In this lesson, we'll learn why this property is useful and unlocks Symbols as appropriate to use to represent strings constants in JS. We'll investigate a use case for string constants and see why using Symbols prior to ES2019 was not appropriate. Then we'll see how using .description fixes that. Lastly, we'll learn why using Symbols may be better than strings for constants in certain use cases by examining what it means to be "collision free".

If we define a Symbol:

const sy = Symbol('A')

Before ES2019, if we console.log `sy`, we will always get `Symbol(A)`.

After ES2019 we can get the value of Symbol:

console.log(sy.description) // 'A'

And Symbol are collision-free which means:

Symbol('a') === Symbol('a') //false

最新文章

  1. ABP 索引
  2. 集成EaseUI报错 环信3.1.5,托入EaseUI后,系统文件报错
  3. c语言数据结构和算法库--cstl---王博--相关网站和博客
  4. 跨服务器之间的session共享
  5. iOS-NSThread使用
  6. c#中如何得到百分比数值
  7. HTML5+开发移动app-mui开发示例
  8. The List ADT
  9. iOS开发常用
  10. javascript模板引擎template.js使用
  11. display:inline-block 来解决盒子高度不一样,造成的盒子浮动
  12. Reactor
  13. 如何将div中的内容设置为空同时还要保留div本身
  14. Shell教程 之test命令
  15. 版本管理(二)之Git和GitHub的连接和使用
  16. iOS开发中FMDB的使用
  17. HTML5/CSS3实现五彩进度条应用
  18. grpc protobuf
  19. Facebook回应追踪无账号用户:源于网站插件漏洞
  20. JSON字符串转换为Map

热门文章

  1. ConcurrentHashMap能完全替代HashTable吗?
  2. 多文件上传,添加重复文件时无法触发onchange事件。
  3. 关于c++模板非类型参数中指针和引用类型必须为全局或者静态变量的问题
  4. 利用Python进行数据分析_Pandas_基本功能
  5. MySQL 数据库连接命令
  6. ndarray笔记
  7. c语言 c++程序运行过程
  8. 通过json_set函数,来修改data字段的值
  9. 2019杭电多校一 C. Milk (dp)
  10. Thread 如何安全结束一个线程 MD