|`sym
|}
=== JavaScript ===
In [[JavaScript]], a symbol is an primary value.<ref>[https://developer.mozilla.org/en-US/docs/Glossary/Symbol MDN Symbol Glossary]</ref> Symbols can be used as identifiers and can be tested for equality just like other primary values. Depending on how the symbol is created they are equal or unequal to another symbol with the same description.
==== Examples ====
A symbol can be created as unique identifier. Creating a symbol using the ''Symbol'' function will always return a unique value. The parameter provided sets the description, but cannot be used to access the symbol itself.<ref>[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol MDN Symbol function]</ref>
<source lang="JavaScript">
const s1 = Symbol();
const s2 = Symbol(42);
const s3 = Symbol('foo');
Symbol('foo') === Symbol('foo');
//=> false
</source>
A symbol can also be created in the global symbol registry using the ''Symbol.for'' method. When calling this method the symbol is looked up in the symbol registry based upon the provided key, if it cannot be found a new symbol will be created and returned.<ref>[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for MDN Symbol.for method]</ref> This method of creating symbols is more comparable with other languages like for example [[#Ruby]].
<source lang="JavaScript">
Symbol.for('bar') === Symbol.for('bar');
//=> true
</source>
The description of both types can be read from the (read-only) ''description'' property. If a non-string description was provided it will be converted to a string (on symbol creation).
<source lang="JavaScript">
Symbol('foo').description;
//=> "foo"
Symbol.for('bar').description;
//=> "bar"
</source>
The symbol key can also be found using the ''Symbol.keyFor'' method.<ref>[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor MDN Symbol.keyFor method]</ref> The symbol key is equal to its description with the exception that unique identifier symbols won't be registered at the global symbol registry and thus don't have a key.
<source lang="JavaScript">
Symbol.keyFor(Symbol('foo'));
//=> undefined
Symbol.keyFor(Symbol.for('bar'));
//=> "bar"
</source>
This can for example be used to check for the difference between a global or unique symbol.
===Lisp===
|