728x90

✨ string을 integer(number)로 바꿔주는 helper method

Reverse Int(숫자 거꾸로 바꾸기) Algorithm에서 유용하게 사용했다.
(string 변환 후 다시 integer로 되돌려야하기 때문이다)

💻Example Code
✅ String와 Number를 비교하는 코드로 작성한다.

const str = '24';

console.log( parseInt(str) );
console.log( str );
console.log( typeof parseInt(str) );
console.log( typeof str );

실행 결과(Number, String) - VS Code Node.js 기준

😋 Reverse Int (숫자 거꾸로 바꾸기) Algorithm을 다룰 때, string 변환 후 최종값을 number로 되돌리기 위해 사용한다.

👉 자세한 내용은 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

'JavaScript > Built-in Method etc.' 카테고리의 다른 글

Array.prototype.reverse()  (0) 2019.12.24
Number.prototype.toString()  (0) 2019.12.24
Math.sign()  (0) 2019.12.24
Array.prototype.slice()  (0) 2019.12.23
Math.floor()  (0) 2019.12.23

+ Recent posts