Skip to content

Instantly share code, notes, and snippets.

@ThaddeusJiang
Created November 7, 2018 06:37
Show Gist options
  • Save ThaddeusJiang/df806cb147f1742f28a53c730d67d1ef to your computer and use it in GitHub Desktop.
Save ThaddeusJiang/df806cb147f1742f28a53c730d67d1ef to your computer and use it in GitHub Desktop.
JavaScript 原始类型(6种)

undefined, null, string, number, boolean, and symbol.

symbol 是 ES6 新定义, 主要概念:

  1. symbol 表示独一无二的值。所以可以用来做对象的属性名。
  2. symbol 通过 Symbol() 函数生成。
  3. symbol 值不能与其他类型的值进行运算。
// Symbol() 函数的参数只是表示 Symbol 值的描述,因此即使参数相同,返回值也不相等。

let s1 = Symbol()
let s2 = Symbol()

s1 === s2 // false

参考:

http://es6.ruanyifeng.com/#docs/symbol

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Data_structures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment