JavaScript Style Guide - Standard Library

Jang Seok Woo·2022년 8월 12일
0

실무

목록 보기
126/136

29. Standard Library

The Standard Library contains utilities that are functionally broken but remain for legacy reasons.

29.1 Use Number.isNaN instead of global isNaN.

eslint: no-restricted-globals

Why? The global isNaN coerces non-numbers to numbers, returning true for anything that coerces to NaN. If this behavior is desired, make it explicit.

// bad
isNaN('1.2'); // false
isNaN('1.2.3'); // true

// good
Number.isNaN('1.2.3'); // false
Number.isNaN(Number('1.2.3')); // true

29.2 Use Number.isFinite instead of global isFinite.

eslint: no-restricted-globals

Why? The global isFinite coerces non-numbers to numbers, returning true for anything that coerces to a finite number. If this behavior is desired, make it explicit.

// bad
isFinite('2e3'); // true

// good
Number.isFinite('2e3'); // false
Number.isFinite(parseInt('2e3', 10)); // true

출처 : https://github.com/airbnb/javascript

profile
https://github.com/jsw4215

0개의 댓글