Search⌘ K

Symbol and Unique Symbol

Explore the concept of Symbols in TypeScript, a primitive type used to create unique and immutable values. Understand how symbols differ from strings, how they work as object property keys, and the special role of unique symbols in creating literal types that prevent collisions. This lesson helps you grasp how symbols improve code safety and uniqueness in your TypeScript projects.

We'll cover the following...

Symbol

Symbol is a primitive type in ECMAScript 2015 and beyond. TypeScript supports the standard. The equal sign assigns a value to a symbol without the keyword new but must have parentheses, like an object. A symbol’s goal is to provide a unique and immutable variable.

A symbol can take a parameter with a string value. Defining two symbols with the same parameter will produce a different symbol. In fact, the parameter is just there to help developers when printing the symbol to the console. It’s a way ...