Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
programming

What is a Dart symbol?

Educative Answers Team

In Dart, a symbol object represents an operator or identifier declared in a Dart program. Symbols cannot be changed as they are compile-time constants. This makes them invaluable for APIs that refer to identifiers by name because minification replaces identifier names, but not identifier symbols.

Symbols are rarely used these days and libraries, like the MirrorSystem that supports them, have been deprecated.

svg viewer
Minification reduces file size to send files over a network

Usage

Prefixing any identifier with # makes it into a symbol literal:

#foo
#bar
// To get the symbol for an identifier, use a symbol literal, which is just # followed by the identifier

The syntax to declare a symbol is:

import 'dart:convert';

void main() {
    Symbol object = new Symbol('name');
    // name must be a valid public Dart member name, public constructor name, or library name.
    print(object);
}

RELATED TAGS

dart
programming
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring