Skip to content

Files

Latest commit

 

History

History
24 lines (18 loc) · 581 Bytes

prefer-native-coercion-functions.md

File metadata and controls

24 lines (18 loc) · 581 Bytes

Pattern: Custom wrapper for type coercion function

Issue: -

Description

Creating custom functions that simply wrap built-in coercion functions like String(), Number(), BigInt(), Boolean(), or Symbol() is unnecessary. Using the built-in functions directly provides the same functionality with better clarity.

Examples

Example of incorrect code:

const foo = (v) => String(v);
foo(1);
const foo = (v) => Number(v);
array.some((v) => /* comment */ v);

Example of correct code:

String(1);
Number(1);
array.some(Boolean);