- boolean
- number (which represents integers and floating points)
- string
- BigInt (ES2020+) to represent whole numbers larger than 2^53 -1, and
- symbol to create unique identifiers
Starting with ES2015, symbol is a primitive type, whose values are created by calling the Symbol constructor.
Examples:
let sym1 = Symbol();
let sym2 = Symbol("keyname");
Symbols are immutable and unique, which can result in what may be initially feel like strange behaviour, but on reflection makes sense.
let sym2 = Symbol("key");
let sym3 = Symbol("key");
sym2 === sym3; // triple equality - false, Symbols are unique.
No comments:
Post a Comment