Well Known Symbols

JavaScript has some built-in symbols which represent internal language behaviours. A well-known symbol is sometimes denoted by @@, eg. @@iterator.

Iteration Iteration Iteration

Symbol.iterator

A method returning the default iterator for an object. Used by for...of.

Symbol.asyncIterator

A method that returns the default AsyncIterator for an object. Used by for await of.

Regular Regular Regular E E E xpression xpression xpression

Symbol.match

A method that matches against a string also used to determine if an object may be used as a regular expression. Used by String.prototype.match().

Symbol.replace

A method that replaces matched substrings of a string. Used by String.prototype.replace().

Symbol.search

A method that returns the index within a string that matches the regular expression. Used by String.prototype.search().

Symbol.split

A method that splits a string at the indices that match a regular expression. Used by String.prototype.split().

Other Other Other s s s

Symbol.hasInstance

A method determining if a constructor object recognizes an object as its instance. Used by instanceof.

Symbol.isConcatSpreadable

A Boolean value indicating if an object should be flattened to its array elements. Used by Array.prototype.concat().

Symbol.unscopables

An object value of whose own and inherited property names are excluded from the with environment bindings of the associated object.

Symbol.species

A constructor function that is used to create derived objects.

Symbol.toPrimitive

A method converting an object to a primitive value.

Symbol.toStringTag

A string value used for the default description of an object. Used by Object.prototype.toString().

You might want to return Array objects in your derived array class MyArray. The species pattern lets you override default constructors.


RESETRUNFULL
<!DOCTYPE html><html><body><script>

class MyArray extends Array {  // Overwrite species to the parent Array constructor
  static get [Symbol.species]() { return Array; }}let a = new MyArray(1,2,3);let mapped = a.map(x => x * x);console.log(mapped instanceof MyArray); // falseconsole.log(mapped instanceof Array);   // true

</script></body><html>