This course has been updated! We now recommend you take the JavaScript: The Recent Parts course.

Check out a free preview of the full ES6: The Right Parts course:
The "Well Known Symbols" Lesson is part of the full, ES6: The Right Parts course featured in this preview video. Here's what you'd learn in this lesson:

Well known symbols are properties on the Symbol object. They include iterator, toStringTag, toPrimitive, and isConcatSpreadable. Kyle spends a few minutes explaining how these symbol properties are used before diving deeper into Symbol.iterator.

Get Unlimited Access Now

Transcript from the "Well Known Symbols" Lesson

>> [MUSIC]

>> Kevin Whinnery: The JavaScript engine ships with a set of what are called well known symbols. They are properties on the symbol function object. So you can access them there. So, for example, there is a special symbol shipped at Symbol.iterator. There's another one called Symbol.toStringTag. There's another one called Symbol.toPrimitive.

[00:00:29] There's another one called Symbol.isConcatSpreadable. So there's all these, there's about a dozen or more of these predefined well known symbols. And the purpose of them being defined by JavaScript, is they are the way that JavaScript tells you, the programmer, the meta hooks for extending built in JavaScript behavior.

[00:00:58] So if I have any object that, for example, is gonna be an iterable, it's gonna be an iterator which we're getting ready to talk about, and I wanna customize the iterator, the location on the object to do that at is at symbol.iterator. If I wanna hook to customize how a thing is stringified whenever you call toString on it, I customize that at the hook location toStringTag.

[00:01:24] If I want to control whether or not an object should be spread if it's passed to the Concat method, I control that with isConcatSpreadable, okay? Are you following me? These are meta extension hooks. That's what they really are. Okay. So these are just built in ones. So if we come over here to the browser, and we ask what is in Symbol.iterator, see they predefined one for us.

[00:01:51] We don't know what its value is, but it doesn't matter because that's the special value, it's a special constant, if you will, that we can use to do a meta extension. Symbol.isConcatSpreadable. Oops. Symbol. What are the other ones? isPrototype. No that's not one. toPrimitive is one, unscopeable is one.

[00:02:24] There's a bunch of them, okay. Like I said there's about a dozen of them. I'm not going to cover any of these well known symbols in any kind of detail. They're covered in exquisite detail in my ES6 book. But we want to zero in our attention for the rest of today on iterators.

[00:02:40] That's the whole reason I talked to you about symbols, is so you know what symbol.iterator is. Okay?