This rule raises an issue when built-in constructors are called without the new keyword (except for String,
Number, Boolean, Symbol, and BigInt which should not use new).
JavaScript allows calling most built-in constructors both with and without the new keyword, but this inconsistency can lead to
confusion and unexpected behavior.
For most built-in constructors like Array, Object, Date, Map, etc., both Array()
and new Array() work the same way. However, using new makes the intent clearer - you are creating a new instance of an
object. This consistency helps other developers understand your code better.
There are important exceptions: String, Number, Boolean, Symbol, and BigInt should
NOT use new. When called without new, these functions convert values to primitive types. When called with new,
they create wrapper objects instead of primitives, which is rarely what you want and can cause unexpected behavior in comparisons and type checks.
For example, new String('hello') creates a String object, while String('hello') creates a primitive string. The object
version behaves differently in boolean contexts and equality comparisons.
Inconsistent constructor usage reduces code readability and maintainability. Using new with primitive wrapper constructors
(String, Number, Boolean) creates wrapper objects that can cause subtle bugs in equality comparisons and type
checks, potentially leading to unexpected application behavior.
Add the new keyword when calling built-in constructors (except for primitive wrapper constructors).
const list = Array(10); // Noncompliant const now = Date(); // Noncompliant const map = Map([['foo', 'bar']]); // Noncompliant
const list = new Array(10); const now = new Date(); const map = new Map([['foo', 'bar']]);