Loading topic
string, number, bigint, boolean, undefined, null, and symbol. Most developers use the first six every day. Many have never called Symbol() on purpose. Symbols are still worth learning, because they are the reason for...of loops work, and they g5 min readtypeof, and that you have read the previous chapter. In that chapter you learned that every call to Symbol() returns a new, unique value. Here you will learn what the text inside Symbol('...') actually does, how to turn a symbol in5 min read{ [expr]: value }) work, and how ES6 classes define methods. It also builds on the previous chapters: every call to Symbol() returns a new, unique value, and 5 min readSymbol() and how to use them as computed property keys ({ [key]: value }). It also assumes you are comfortable with Object.keys, for...in, spread syntax, and JSON.stringify.5 min readSymbol() creates a value that is never equal to any other symbol. That uniqueness prevents name collisions. It also causes a problem when two separate pieces of code need to agree on the same symbol and cannot import it from a shared place. The global sym6 min readfor...of loops, and spread syntax. It also assumes you have read the earlier chapters on symbols as property keys and on well-known symbols. Generator functions (function*) appear throughout. You only need to know that yield h5 min readSymbol.iterator lets for...of pull values from an object one at a time. That only works when each value is ready the moment it is asked for. A lot of data arrives late: pages from an API, chunks from a file, messages from a socket. Symbol.asyncIterator is the we5 min readvalueOf and toString work on ordinary objects, and how computed property names and class methods are written. Earlier chapters introduced well-known symbols as hooks into the language. This chapter covers one of them in detail: `Sym4 min readObject.prototype.toString builds strings like "[object Array]", how Symbol.toStringTag chang5 min readinstanceof actually decides its answer, how Symbol.hasInstance replaces that decision, and the traps that make th6 min readObject.getOwnPropertySymbols and Reflect.ownKeys list them. You should also be comfortable with ES6 classes, getters, and the idea of an object's identity, meaning that two objects are equal only when they are the 6 min readWeakMap and WeakSet work. That means you know that keys must be values the garbage collector can reclaim, and that weak collections are not iterable. It also assumes you know the difference between Symbol() and Symbol.for() from the chapter on the global reg5 min readSymbol() and Symbol.for() differ, which operations skip symbol keys, how Symbol.iterator works, and why symbols do not give privacy. The focus here is on deciding when 4 min read