반응형
공통점
- 문자열 숫자를 정수 숫자로 만들어준다. (string -> int)
- 숫자로 이뤄지지 않은 문자열이라면 NaN을 반환한다.
차이점
- parseInt('') ➡️ NaN
- +'' ➡️ 0
https://stackoverflow.com/questions/17106681/parseint-vs-unary-plus-when-to-use-which
parseInt vs unary plus, when to use which?
What are the differences between this line: var a = parseInt("1", 10); // a === 1 and this line var a = +"1"; // a === 1 This jsperf test shows that the unary operator is much faster in the cur...
stackoverflow.com
반응형
'Front-End: Web > JavaScript' 카테고리의 다른 글
[js] sort() vs sort((a,b) => a - b) (0) | 2022.09.11 |
---|---|
[js] NaN(Not A Number)이란? (+isNaN, Number.isNaN) (0) | 2022.09.10 |
[js] Math - ceil, floor, round (+ trunc) (0) | 2022.09.10 |
[js] 문자열.repeat() 안에 정수가 아닌 수를 넣으면? (0) | 2022.09.10 |
[js] 문자열 자르기 (slice, splice, split, substring, substr) (0) | 2022.09.10 |