Lesson 13. Symbol—a new primitive

After reading lesson 13, you will

  • Know how to use symbols as constants
  • Know how to use symbols as object keys
  • Know how to create behavior hooks with global symbols
  • Know how to modify object behavior with well-known symbols

In JavaScript there are objects and there are primitives. The primitives of JavaScript are strings, numbers, Booleans (true or false), null, and undefined. Symbol is a new primitive added in ES2015 and is the first primitive added to JavaScript since its creation. A symbol is a unique value that’s used for hooking into the behavior of built-in JavaScript objects. Symbols can be broken into three categories:

  1. Unique symbols
  2. Global symbols
  3. Well-known symbols
Consider this

Get Get Programming with JavaScript Next now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.