Symbol is a data type used to represent a unique, named, or interned identifier.

Symbols are often used when identity matters more than text content. They can be useful as keys, tags, or lightweight identifiers.

Examples include:

  • Symbols in Ruby, such as :name
  • Symbols in JavaScript, such as Symbol("name")
  • Symbols in Lisp-like languages

Symbols are useful for:

  • Object keys
  • Message names
  • Identifiers
  • Avoiding accidental string collisions

A symbol is different from a string because it is usually treated as an identifier rather than arbitrary text.

Anki

id: symbol-definition deck: Computer Science::Data Types tags: data-types symbol

Q: What is a symbol? A: A symbol is a data type used to represent a unique, named, or interned identifier.

id: symbol-vs-string deck: Computer Science::Data Types tags: data-types symbol string

Q: How is a symbol different from a string? A: A symbol is usually treated as an identifier, while a string is arbitrary text.