Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 530 Bytes

new-for-builtins.md

File metadata and controls

21 lines (15 loc) · 530 Bytes

Pattern: Incorrect use of new with built-in objects

Issue: -

Description

Some built-in objects require new for consistency (e.g., Array, Map, Set), while others should not use new to avoid creating object wrappers for primitives (e.g., String, Number, Boolean).

Examples

Example of incorrect code:

const foo = new String("hello world");
const bar = Array(1, 2, 3);

Example of correct code:

const foo = String("hello world");
const bar = new Array(1, 2, 3);