Back to Eslint

no-new-symbol

docs/src/rules/no-new-symbol.md

10.3.0723 B
Original Source

Symbol is not intended to be used with the new operator, but to be called as a function.

js
var foo = new Symbol("foo");

This throws a TypeError exception.

Rule Details

This rule is aimed at preventing the accidental calling of Symbol with the new operator.

Examples of incorrect code for this rule:

::: incorrect

js
/*eslint no-new-symbol: "error"*/

var foo = new Symbol('foo');

:::

Examples of correct code for this rule:

::: correct

js
/*eslint no-new-symbol: "error"*/

var foo = Symbol('foo');

// Ignores shadowed Symbol.
function bar(Symbol) {
    const baz = new Symbol("baz");
}

:::

When Not To Use It

This rule should not be used in ES3/5 environments.